Data extraction and indexing of array

1 visualización (últimos 30 días)
Arsal15
Arsal15 el 6 de Ag. de 2020
Comentada: Sudheer Bhimireddy el 7 de Ag. de 2020
Hi,
I have a structure of 1x5 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 1x51. 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
  1 comentario
Arsal15
Arsal15 el 6 de Ag. de 2020
Secondly, I should use scatter or plot to plot all those data sets ?

Iniciar sesión para comentar.

Respuesta aceptada

Sudheer Bhimireddy
Sudheer Bhimireddy el 6 de Ag. de 2020
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
  2 comentarios
Arsal15
Arsal15 el 7 de Ag. de 2020
Hi Sudheer Bhimireddy,
I tried this solution and error is same. I have attached new NP.mat with x,y data has different length.
Sudheer Bhimireddy
Sudheer Bhimireddy el 7 de Ag. de 2020
My bad. Before the for loop the xposdata and similar variables are already initialized.
Change them to:
xposdata = cell(nid,1);
yposdata = cell(nid,1);
velxposdata = cell(nid,1);
velyposdata = cell(nid,1);

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by