I have two matrices which are 200*5 and 201*5. I want to plot a graph from these two matrices. as X component is from the one, Y component is from the other. I have an algoritm below. When I select the line as a star (*), it is plotted but I want it as a line. How can I do it? Thank you.
%for plotting
[row col]=size(Vdt);
for m=1:col
for n=1:row-1
hold on
plot(t(n,m),Vdt(n,m),"*")
end
end

 Akzeptierte Antwort

the cyclist
the cyclist am 10 Okt. 2022
Bearbeitet: the cyclist am 10 Okt. 2022

0 Stimmen

If you leave the marker symbol off, the plot command will default to using a solid line with no symbol. You can also just explicitly specify a solid line with no symbol:
plot(t(n,m),Vdt(n,m),"-")
You can read more in the documentation for the plot function, in particular this example (and ones following) from that same page.

7 Kommentare

Ali Deniz
Ali Deniz am 10 Okt. 2022
It doesn't work. I tried it. I think, since ,in the plot command, the x and y components are selected as a point, the plot does not plot the graph as a line. Thank you.
Sorry, I did not read your code closely enough.
The problem is that you are not plotting vectors. Each call to the plot function is plotting just a single point, so there is no "line" for the plot command.
Instead, you need to structure your code so that you are plotting all the point of each line in a single plot command, instead of looping over each point. It might be like this:
%for plotting
figure
hold on
[row col]=size(Vdt);
for m=1:col
plot(t(:,m),Vdt(:,m),"-")
end
If that connects the wrong set of points, then you should loop over n instead of m.
If you post your data, it would be easier to know for sure.
Ali Deniz
Ali Deniz am 10 Okt. 2022
The matrices is in attachments. There is zero values in the matrices and I want to match the Vdt values to the t values correctly. So that I write a algorithm like that. Thank you.
the cyclist
the cyclist am 10 Okt. 2022
I don't understand what you mean by "match the Vdt values to the t values correctly".
That part of your algorithm is completely unrelated to the question you asked here. I suggest you open a new question about the algorithm. You should add more detail about exactly what you are trying to do.
Ali Deniz
Ali Deniz am 10 Okt. 2022
Okey, thank you. I think I must change structure of my code.
Steven Lord
Steven Lord am 10 Okt. 2022
Another possibility, if the points are generated one at a time, is to use some of the animation techniques available in MATLAB, like creating an animatedline and using addpoints to add points to the line as they are calculated or creating a normal line with line or plot and adding values to the line's XData and YData properties as they're calculated.
Ali Deniz
Ali Deniz am 10 Okt. 2022
That's good idea also. Thank you.

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

Community Treasure Hunt

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

Start Hunting!

Translated by