Plotting graph from the values of a 15x3 matrix

1 view (last 30 days)
Hi!
I have a problem. I have a matrix 15x3 consisting of values:
P T C
1 30 3.4
1 40 3.5
1 50 3.6
2 30 3.41
2 40 3.51
2 50 3.61
3 30 3.42
3 40 3.52
3 50 3.62
4 30 3.43
4 40 3.53
4 50 3.63
5 30 3.44
5 40 3.54
5 50 3.64
I want to plot a graph P vs.C depending on the T values. For example, if the T value is 30, I want the graph to point all P vs C values at that T.
Then for 40,50,60 T the same thing.
(I just made up the numbers, So the graph should look like one of these;

Accepted Answer

David Hill
David Hill on 30 Mar 2021
figure;
hold on;
for k=[30 40 50 60]
plot(m(m(:,2)==k,1),m(m(:,2)==k,3));%m beig your maxtix
end

More Answers (1)

DGM
DGM on 30 Mar 2021
Something like this:
PTC=[1 30 3.4;
1 40 3.5;
1 50 3.6;
2 30 3.41;
2 40 3.51;
2 50 3.61;
3 30 3.42;
3 40 3.52;
3 50 3.62;
4 30 3.43;
4 40 3.53;
4 50 3.63;
5 30 3.44;
5 40 3.54;
5 50 3.64];
T=[30 40 50];
clf
legendstrings=cell([1 length(T)]);
for t=1:length(T)
% note the limitations of this equality test
% this might work if T(t) is an integer
% but it might be better to test within a tolerance
PC=PTC(PTC(:,2)==T(t),[1 3]);
h(t)=plot(PC(:,1),PC(:,2)); hold on
legendstrings{t}=sprintf('T=%d',T(t));
end
legend(h,legendstrings)
gives this:

Community Treasure Hunt

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

Start Hunting!