why do I always receive the error: Unrecognized function or variable 'Pt'.
이전 댓글 표시
function [Cout,iter_time] = PGM_opt(Pt,Hdir,H1,H2,maxIter,Qinit,myomegaunitball,c)
댓글 수: 17
Dyuman Joshi
2023년 1월 5일
편집: Dyuman Joshi
2023년 1월 5일
Please show your full code, how you call the function and the full error.
Dyuman Joshi
2023년 1월 5일
You still haven't attached how you call the function and what the full error is.
LoCi
2023년 1월 6일
@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
2023년 1월 7일
Voss
2023년 1월 7일
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
2023년 1월 7일
Walter Roberson
2023년 1월 7일
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
2023년 1월 8일
Voss
2023년 1월 8일
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
2023년 1월 8일
Jan
2023년 1월 8일
@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
2023년 1월 8일
@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
2023년 1월 9일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
