How can I read a column from excel while I do not want all the data of that column?

1 visualizzazione (ultimi 30 giorni)
I want to plot four graphs in the same figure. I can read all of them from excel. But for first plotting i want to plot all the values of X; but the second plot I want to take the values after 5 intervals, the step size should be suppose 5, something like xmin:5: xmax. how i can do that?
X=readmatrix('phasesintegrated','Range','A2:A106');
Y1=readmatrix('phasesintegrated','Range','B2:B106');
Y2=readmatrix('phasesintegrated','Range','C2:C106');
plot(X,Y1, 'color','b','linewidth',2);
plot(X,Y2, 'Marker','o', 'color','b','linewidth',1);

Risposte (1)

dpb
dpb il 31 Ago 2022
It's VERY inefficient to open/read/close the same file three times, not to mention it just makes for more work to address multiple variables with sequentially-number names. The existence of such is a very good sign that MATLAB syntax isn't being used effectively.
Instead, do something more like
data=readmatrix('phasesintegrated'); % read the whole array at once
plot(data(:,1),data(:,2),'b-','linewidth',2);
hold on % so can add to same axes
plot(data(:,1),data(:,3), 'bo-','linewidth',1);
Not sure what else, specifically you want to plot, but the "every fifth point" thing is trivial -- see <colon, :> for all the skinny on subscripting, but
nSkip=5;
plot(data(1:nSkip:end,1),data(1:nSkip:end,2),'rx');
would add the 2nd set of data with a red 'x' for every fifth point beginning with the first. You can change the starting index at will, too, of course.

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by