Plotting all the columns of a matrix

Hi,
I want to plot columns of two matrices Z_imag and Z_real in two separate graphs.
I tried to do this code but I wasnt able to:
Z_imag=randi(10,10,3);
Z_real=randi(10,10,3);
width_mil=1:10
for i=1:1:3
figure(1)
Z_im = axes;
plot( Z_im,width_mil,Z_imag(:,i),'-o');
title('Imaginary part of the impedance');
xlabel('W [mil]');
ylabel('Im{Z}');
figure(2)
Z_re = axes;
plot(Z_re,width_mil,Z_real(:,i),'-o');
title('Real part of the impedance');
xlabel('W [mil]');
ylabel('re{Z}');
end

2 Comments

Can you upload your data in a MAT file, so that we can execute your code?
Thank you, I have added more information to the code
Z_imag=randi(10,10,3);
Z_real=randi(10,10,3);
width_mil=1:10
for i=1:1:3
figure(1)
Z_im = axes;
plot( Z_im,width_mil,Z_imag(:,i),'-o');
title('Imaginary part of the impedance');
xlabel('W [mil]');
ylabel('Im{Z}');
figure(2)
Z_re = axes;
plot(Z_re,width_mil,Z_real(:,i),'-o');
title('Real part of the impedance');
xlabel('W [mil]');
ylabel('re{Z}');
end
Could you help with this edited code

Sign in to comment.

 Accepted Answer

I want to plot columns of two matricesZ_imag and Z_real in two separate graphs.
I assumed, stack bar plot of individual column elements:
matricesZ_imag=rand(4,5);
Z_real=randi(10,4,5)
figure,bar(matricesZ_imag','stacked');
figure,bar(Z_real','stacked');

10 Comments

Thank you for your answer, But I want to plot continous graphs not bar graphs
Z_imag=randi(10,10,3);
Z_real=randi(10,10,3);
width_mil=1:10
for i=1:1:3
figure(1)
Z_im = axes;
plot( Z_im,width_mil,Z_imag(:,i),'-o');
title('Imaginary part of the impedance');
xlabel('W [mil]');
ylabel('Im{Z}');
figure(2)
Z_re = axes;
plot(Z_re,width_mil,Z_real(:,i),'-o');
title('Real part of the impedance');
xlabel('W [mil]');
ylabel('re{Z}');
end
I have added the required data to the code. Could you help me to plot
Suppose you have the following matrix (example)
>> mat=randi(5,2,3)
mat =
3 3 1
4 2 1
Can you show the expected result from above matrix? Use paint or any image drawing tool.
mat=[3 3 1;4 2 1];
plot(mat);
% Set the axies levels accordingly (as per your requirements)
I hope, now you can plot two figure for two different matrices, use figure.
Thank you very much I want other vector "width_mil" as x axis
So i want to plot the arrays Z_real and Z_imag vs width_mil
Suppose
Z_real=[3 3 1;4 2 1];
width_mil=??? % Simple Example, result expected??
Just focus on one graph, Z_real vs width_mil, you can easily replicate the same for other Z_imag vs width_mil
Sorry for not making my question clear.
Z_real=[3 3 1;4 2 1;2 1 3];
width_mil=[4,8,12]; I have plotted below the example plot for the arrays I have selected
Capture.JPG
Z_real=[3 3 1;4 2 1;2 1 3]
width_mil=[4,8,12]
plot(width_mil,Z_real);
axis([0,12,0,4])
I hope, your question has been answered!
Thank you ver much for your solution. It works
Its my pleasure, Vinay!

Sign in to comment.

More Answers (1)

madhan ravi
madhan ravi on 29 Aug 2019
Edited: madhan ravi on 29 Aug 2019
No loops needed:
plot(mat)
axis([0,5,0,5])

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2019a

Community Treasure Hunt

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

Start Hunting!