Hey, When I plot from a csv file like so:
K=csvread(b);
plot(K);
I get the correct outcome but the x axis is not the first column as I would like it to be. So I tried this and it didn't work for some reason:
M=csvread(a);
x=M(:,1);
y=M(:,2);
l=M(:,3);
figure (1)
plot(x,y,'g');
hold on
plot(x,l,'r');
I do get a graph with the correct x axis, but the graph is missing many points unlike the previous way where it had all 700000 points. Do I have too many columns for the second way to work? I am using MATLAB 2013b. Thanks

2 Kommentare

Image Analyst
Image Analyst am 21 Jul. 2018
You forgot to attach the files you're using for the badly-named a and b. Please attach them so we can try it and see what the difference is.
Haris Kioleidis
Haris Kioleidis am 21 Jul. 2018
Ok sorry, I thought it could be some known limitation/problem. Here is the file. A and B is practically the same and the problem happens with all my .csv files.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

dpb
dpb am 21 Jul. 2018
Bearbeitet: dpb am 21 Jul. 2018

1 Stimme

The first syntax per the documentation plots all columns of K versus ordinal number
You're on the right track with the second; you don't need the temporaries nor two calls to plot() however...
M=csvread(...;
plot(M(:,1), M(:,2:end))
will plot all columns from 2nd on vs the first; plot will use all points other than any which are NaN that are silently ignored; probably the difference in what you think is number of plotted points is that in the first case the x-axis scale will go to cover 1:N whereas in the second it will be scaled to the value of the elements in the first column which one presumes are not 1:length(M).
What does
sum(isfinite(M))
return at the command line??
Beyond that we'd have to see the data to be able to say anything more...
NB: There's little real point in plotting 700K points, even the most high resolution and largest monitor won't have more than a few K pixels so there's nowhere near enough to display all the points without serious aliasing. Decimating or decimating with bounding or the like would be a logical thing to do here...
ADDENDUM
The problem is that you didn't save enough precision in the input file to record the data accurately.
>> arrayfun(@(i) length(unique(m(:,i))),[1:3],'uniform',1)
ans =
5140 60 35
>>
Whether the 2nd/3rd columns are supposed to be more than such a few different values I don't know, but clearly the first column was supposed to be a time vector and it simply isn't precise enough for the size of the data.
Don't know who wrote the file, but there's where the basic problem comes from, not from plot()

5 Kommentare

Haris Kioleidis
Haris Kioleidis am 21 Jul. 2018
Bearbeitet: Haris Kioleidis am 21 Jul. 2018
I get this at the command line: ans =
700012 700012 700012
Also, I uploaded the file. When I plot with the first syntax I get decent enough resolution and can work some things out but the x axis, as you said, is the ordinal number which I can't use. Thanks
dpb
dpb am 21 Jul. 2018
>> x=linspace(3,1E6,700000).';
>> y=randn(siz e(x));
>> m=[x y y+10];
>> hL=plot(m(:,1), m(:,2:end));
>> x=get(hL,'XData');
>> cellfun(@length,x)
ans =
700000
700000
>>
plot() put all 700K on there...what does that do on your system?
Here are the two graphs of the same file. Full is with
L=csvread(a);
plot(L);
and missing with
L=csvread(a);
plot(L(:,1), L(:,2:end))
dpb
dpb am 21 Jul. 2018
And I downloaded you file and plotted it and did the same test...
subplot(2,1,1)
hL1=plot(m);
x1=get(hL1,'XData');
cellfun(@length,x1)
ans =
700012
700012
700012
subplot(2,1,2)
hL2=plot(m(:,1),m(:,2:end));
x2=get(hL2,'XData');
cellfun(@length,x2)
ans =
700012
700012
>>
which shows it plotted all points either way...the appearance is a result of the fact you didn't save the data with sufficient precision for the first column--
u=unique(m(:,1));
numel(u)
ans =
5140
length(m(:,1))/numel(u)
ans =
136.1891
so there are on average 136 values plotted on top of each other with m(:,1) as the x vector.
Haris Kioleidis
Haris Kioleidis am 22 Jul. 2018
Yeah, got it. Thanks a lot for the help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2013b

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by