Hello,
I am having trouble getting plot() to work. My code works if I use scatter() instead of plot(). If I used plot(), then I get Error in plot(x,y). Can someone please tell me why plot is not working? Thanks!
x = 1:10;
y = x.^2;
figure
hold on
plot(x,y)
hold off

댓글 수: 6

Steven Lord
Steven Lord 2018년 11월 1일
What is the FULL text of the error message you receive? Show everything displayed in red.
Kateri Kaminski
Kateri Kaminski 2018년 11월 1일
My full error is:
Error in PostProcessing_filetest (line 269)
plot(x,y)
Image Analyst
Image Analyst 2018년 11월 1일
편집: Image Analyst 2018년 11월 1일
No, that's not EVERYTHING in red. Most importantly, the actual error message is not there. Please include everything. Put
clc
as the first line in your code, then copy the entire contents of the command window (after it errors) and paste it back here. For me the code runs and products this:
KSSV
KSSV 2018년 11월 2일
I suspect...he have another function on the name plot. He is not using inbuilt function plot. What does which plot display?
Walter Roberson
Walter Roberson 2018년 11월 2일
My guess is that there is a variable named plot
Kateri Kaminski
Kateri Kaminski 2018년 11월 2일
This is the full error. I am not sure why there is an indexing issue.
>> PostProcessing_filetest
Index exceeds matrix dimensions.
Error in PostProcessing_filetest (line 287)
plot(x,y)

댓글을 달려면 로그인하십시오.

 채택된 답변

madhan ravi
madhan ravi 2018년 11월 2일
편집: madhan ravi 2018년 11월 2일

0 개 추천

Delete another .m file which has the same name plot.m or rename it

댓글 수: 9

Kateri Kaminski
Kateri Kaminski 2018년 11월 2일
Thank you! Deleting plot.m and rerunning it seems to work. However, if I want to create plots using a loop, will this cause an issue?
madhan ravi
madhan ravi 2018년 11월 2일
편집: madhan ravi 2018년 11월 2일
Anytime :) Nie ma za co! no it won’t cause any problem if and only if you know to use it properly.
Ok I am trying to run plots in a for loop here. The figure pops up and so does the first subplot but I get the same error (Index exceeds matrix dimensions. Error in PostProcessing_filetest (line 281) plot(y,xt(:,:,i,j)) ) It runs perfectly fine if I used scatter() instead of plot() though. There is no plot.m defined beforehand so I'm wondering if its my loop.
for j = index
figure(fignum)
fignum = fignum + 1;
hold on
for i = 1:numfiles
subplot(numfiles,1,i)
y = Farray(2:end);
yt = transpose(y);
x(:,:,i,j) = NewAmp(:,:,i,j);
xt(:,:,i,j) = transpose(x(:,:,i,j));
xlabel('Frequecy(Hz)')
ylabel('Amplitude')
plot(y,xt(:,:,i,j))
end
hold off
end
madhan ravi
madhan ravi 2018년 11월 2일
Without datas it is hard to interpret , it would be better if you post a new question with all the necessary details
Steven Lord
Steven Lord 2018년 11월 2일
Based on the error message you posted you haven't defined your own function named plot, but you have created a variable named plot earlier in this script or function (or in the caller workspace if this is a script file.) In that case the last line of that for loop becomes an attempt to index into that variable rather than an attempt to call the function.
Kateri Kaminski
Kateri Kaminski 2018년 11월 2일
That makes sense. Do you know why scatter() works then? This loop is the first time I am using plot() so I am not sure why that would be any different than scatter(). I could post more of the script but the entire one is close too 300 lines long. Thanks!
Walter Roberson
Walter Roberson 2018년 11월 2일
You can attach the script.
Stephen23
Stephen23 2018년 11월 3일
"That makes sense. Do you know why scatter() works then? This loop is the first time I am using plot() so I am not sure why that would be any different than scatter()."
Because you created a variable named plot, but did not create a variable named scatter.
Kateri Kaminski
Kateri Kaminski 2018년 11월 5일
Ok thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2018년 11월 1일

댓글:

2018년 11월 5일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by