# Plotting data of a 3x1xn array

27 views (last 30 days)
Rashmil Dahanayake on 3 Jan 2014
Edited: Rashmil Dahanayake on 3 Jan 2014
Hi, I saved data of a simulation in to a 3x1xn cell array.
How can I plot each 3x1 instance Vs time. At the moment I manually saved data in to 3 separate variables in order to plot.
There could be a way to plot by extracting data straight from a n dimension cell.
refer to the comments on subplot(2,1,1)
clc;
clear all;
% Simulation settings
st=0.4; % simulation period in seconds
Ts=1e-6; % sampling period in seconds
t=0:Ts:st;
m=1;fo=50;
% initialize variables to increase simulation speed
o=zeros(1,numel(t));
d=zeros(1,numel(t));
q=zeros(1,numel(t));
for k=1:numel(t)
x=2*pi*fo*k*Ts; % theta
T= [1/2 1/2 1/2 ;... % transfer matrix
cos(x) cos(x-2*pi/3) cos(x+2*pi/3);...
sin(x) sin(x-2*pi/3) sin(x+2*pi/3)];
% 3 phase input signal
U=2/3*m*sin([x ; x- 2*pi/3 ; x+ 2*pi/3 ]);
% store values in 0dq matrix
o(k)=T(1,:)*U;
d(k)=T(2,:)*U;
q(k)=T(3,:)*U;
% odq(:,:,k)=T*U; % saving in to a cell array
end
% subplot(2,1,1);plot(t,odq); % what is the correct way plotting cell
% object defined in for loop.
subplot(2,1,1);plot(t,[o; d; q]);
y=2*pi*fo*t; % theta
U2=m*sin([y ; y- 2*pi/3 ; y+ 2*pi/3 ]);
subplot(2,1,2);plot(t,U2)

Walter Roberson on 3 Jan 2014
Your odq is not a 3 x 1 x n cell array: it is a 1 x n cell array that contains 3 x 1 matrices.
You have 3 values per element of t; how do you want them plotted? Do you want t on the x axis and three separate lines, one consisting of the first coordinates connected, one of the second, one of the third ?
Rashmil Dahanayake on 3 Jan 2014
I think the correct definition should be odq(:,:,k) which is a 3 dimension matrix.
I need to plot. X axis: t values Y axis : 3 elements of dqo
(The output should look like subplot(2,1,1). run the attached m-code. I used manual method to save data instead of cell.)

Walter Roberson on 3 Jan 2014
plot(t, horzcat(odq{:}).' )

#### 1 Comment

Rashmil Dahanayake on 3 Jan 2014
It worked.