MATLAB: Data extraction and indexing of array

data extractionMATLABmatrix manipulation

Hi,
I have a structure of 1×5 and I want to extract X and Y position data of each individual in a single variables like posxdata, posydata, velxdata, velydata, against nid. The nid can range from 1 to 5000 depending upon the time duration.
Since here all the nid [1 to 5] has x and y values of 1×51. Kindly let me know if they have different values like
nid(1) =length(x) = 51 nid(1) =length(y) = 51
nid(2) =length(x) = 43 nid(2) =length(y) = 43
nid(3) =length(x) = 29 nid(3) =length(y) = 29
nid(4) =length(x) = 91 nid(4) =length(y) = 91
nid(5) =length(x) = 81 nid(5) =length(y) = 81
I have written this simple program to extract data. But I am facing dimension mismatch issue.
nid = 5;
xposdata = np.x;
yposdata = np.y;
for i= 1:nid
for j = 1: length(xposdata|yposdata)
xposdata(i,j) =np(i).x(1:end)
yposdata(i,j) =np(i).y(1:end)
velxposdata(i,j) =np(i).vx(1:end)
velyposdata(i,j) =np(i).vy(1:end)
end
end
nid = 5;
xposdata = np.x;
yposdata = np.y;
velxposdata= np.v_x;
velyposdata= np.v_y;
for i= 1:nid
for j = 1: length(xposdata|yposdata)
xposdata(i,j:end) =np(i).x(1:end);
yposdata(i,j:end) =np(i).y(1:end);
velxposdata(i,j:end) =np(i).v_x(1:end);
velyposdata(i,j:end) =np(i).v_y(1:end);
end
end
I need your guideline and recommendation of some short course which can develop understanding of data extraction and manipulation. Mat file is attached thanks
Thanks

Best Answer

If your data size changes throughout the structure then load them into a cell array and access each entry.
nid = 5;
xposdata = np.x;
yposdata = np.y;
velxposdata= np.v_x;
velyposdata= np.v_y;
for i= 1:nid
xposdata{i} = np(i).x(1:end);
yposdata{i} = np(i).y(1:end);
velxposdata{i} = np(i).v_x(1:end);
velyposdata{i} = np(i).v_y(1:end);
end
% for plotting them
h=figure;
clf;
hold on;
for i =1:nid
x = xposdata{i};
y = yposdata{i};
plot(x,y);
end