Data extraction and indexing of array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Arsal15
le 6 Août 2020
Commenté : Sudheer Bhimireddy
le 7 Août 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
Réponse acceptée
Sudheer Bhimireddy
le 6 Août 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 commentaires
Sudheer Bhimireddy
le 7 Août 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);
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!