Hi, I want to plot from spectrum.mat file but it giving me following error. Error using plot Invalid first data argument. Error in data (line 5) plot('spectrum.mat')
But when I exactly load this file then it loading and at right in 'workspace box' giving "spec 401x2 double" values.
Could anyone please let me know that why I can't plot this "spectrum.mat" file, kindly if someone show me the procedure for plotting .mat files. By the way in this spectrum.mat file there are two columns (e.g x-axis Frequency and y-axis Scale) and 401 rows.
Thanks

 Accepted Answer

Jan
Jan on 26 Apr 2017
"plot('spectrum.mat')"?! This tries to plot the char vector 'spectrum.mat'.
You cannot plot a file. You have to load the data at first:
Data = load('spectrum.mat');
Now you can plot the data, perhaps by:
plot(Data.spec)
Or
plot(Data.spec(:,1), Data.spec(:,2))

7 Comments

Hey Jan Simon,
Thanks a lot for the answer, following command is working plot(Data.spec(:,1), Data.spec(:,2)) not plot(Data.spec)
Many thanks, if you have time can you please just let me know that if I have let suppose nine .mat files then how can I merge this in one plot? Sorry to asking you again :(
AxesH = axes('NextPlot', 'add'); % See: hold on
Folder = 'C:\Temp'; % Adjust
for iFile = 1:9
File = fullfile(Folder, sprintf('YourFile%d.mat', iFile));
Data = load(File)
plot(AxesH, Data.spec(:,1), Data.spec(:,2))
end
Here I guess, that your files are called "YourFile1.mat", "YourFile2.mat" etc. Please adjust this.
CVIl
CVIl on 5 Oct 2020
What does (:,1) and (:,2) mean and what is the purpose? If you need to obtain the x,y values at a specific point, how does this change the plot(Data.spec(:,1), Data.spec(:,2)) command line?
CVII:
Notice the user said spec 401x2 double" and said "there are two columns (e.g x-axis Frequency and y-axis Scale) and 401 rows."
So the file contains a variable named spec and the first column is x and the second column is y -- this information was given by the user. So we access the x by accessing the first column, the MATLAB notation for which is (:,1), and the y by accessing the second column, the MATLAB notation for which is (:,2)
If you need to obtain the x,y values at a specific point
How would that point be described? Would you be looking for a particular row, or would you be searching for closest to a particular x, or would you be giving an x y pair and asking which point is closest to that x, y ?
CVIl
CVIl on 5 Oct 2020
Does the 'x2' portion of 401x2 double indicate there are 2 columns? I would like to plot stress versus time and have fields of size [4853x200 double]. In this case do I have 200 columns? Can I use the plot(Data.spec(:,1), Data.spec(:,2)) command with this field size?
For the points I was not given x,y, I am looking for specific nodal points.
Yes, the x2 indicates two columns. This is standard output format for "whos", the dimension sizes separated by 'x'
You do appear to have 200 columns.
You can use that syntax, provided that the name of the saved variable is spec and you assign the result of load() to the variable named Data
However, I suspect that would be the wrong thing to do. I suspect that you have either 4853 stress sites sampled at 200 times, or else 200 stress sites sampled at 4853 times. I suspect you should use something more like a waterfall plot.
Hi, I'm using 3 variables and it gives me error saying tabular/plot and tells me to use stackedplot function. Can you help me with this?

Sign in to comment.

More Answers (1)

Moiz Tariq
Moiz Tariq on 5 Dec 2018
Edited: Moiz Tariq on 5 Dec 2018

2 votes

See tthe name of file in workspace
let's say the name is wwe
write in comand window
[load'wwe.mat'
x=wwe(:, 1)
y=wwe(:,2)
plot(x,y)]

Categories

Community Treasure Hunt

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

Start Hunting!