why do I always receive the error: Unrecognized function or variable 'Pt'.
Show older comments
function [Cout,iter_time] = PGM_opt(Pt,Hdir,H1,H2,maxIter,Qinit,myomegaunitball,c)
17 Comments
Dyuman Joshi
on 5 Jan 2023
Edited: Dyuman Joshi
on 5 Jan 2023
Please show your full code, how you call the function and the full error.
Dyuman Joshi
on 5 Jan 2023
You still haven't attached how you call the function and what the full error is.
LoCi
on 6 Jan 2023
@SAFA AWAD: I copied and pasted your code into an .m file (attached), and it runs without error (until the last line "print('../results/Achievable_Rate', '-dpdf')", which generates an error because I don't have a "../results/" folder).
No error about Unrecognized Pt or execution of varargin is observed.
Here it is running now:
test_script
LoCi
on 7 Jan 2023
Voss
on 7 Jan 2023
As I said, the only error I ran into was due to not having a "../results" directory, so the SOLUTION would be, either:
- Create a directory called "results" under the directory one level up from where you are running the code, so that "..\results" exists, or
- Modify the line "print('../results/Achievable_Rate', '-dpdf')" to print to a directory that exists.
LoCi
on 7 Jan 2023
Walter Roberson
on 7 Jan 2023
There would have been more to the error message, showing which lines the problem was occurring in. The posted code does not use varargin so the problem must be with something that is being called, but we need the complete error message to figure out what.
LoCi
on 8 Jan 2023
Voss
on 8 Jan 2023
Is there a directory called "results" under the directory one level up from where you are running the code, so that "../results" exists?
Example: if code is running in "/home/projects", print would try to create "/home/results/Achievable_Rate.pdf", so the directory "/home/results" needs to exist beforehand.
LoCi
on 8 Jan 2023
Jan
on 8 Jan 2023
@SAFA AWAD: It depends on what "from where I am running the code" means. If this is the current folder:
folder = cd;
If you mean the folder of the M-file:
folder = fileparts(mfilename('fullpath'));
The rest is equal in both cases:
mkdir(fullfile(folder, '..', 'results'))
Voss
on 8 Jan 2023
@SAFA AWAD: Jan is correct; that's how you can do it in MATLAB.
An alternative would be to go into your operating system's File Explorer and create the folder, e.g., on Windows right-click and select 'New Folder' and rename it 'results'.
The point is that the folder has to exist before you try to write a pdf file in it.
Or you can change where the pdf file should go, e.g., to put in the working directory:
print('Achievable_Rate','-dpdf')
LoCi
on 9 Jan 2023
Answers (0)
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!