Data extraction and indexing of array

조회 수: 1 (최근 30일)
Arsal15
Arsal15 2020년 8월 6일
댓글: Sudheer Bhimireddy 2020년 8월 7일
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
Arsal15
Arsal15 2020년 8월 6일
Secondly, I should use scatter or plot to plot all those data sets ?

댓글을 달려면 로그인하십시오.

채택된 답변

Sudheer Bhimireddy
Sudheer Bhimireddy 2020년 8월 6일
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
Arsal15
Arsal15 2020년 8월 7일
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 2020년 8월 7일
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);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by