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.
Kateri Kaminski
Kateri Kaminski 2018 年 11 月 2 日
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 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by