Problem with filling a variable inside loops

1 回表示 (過去 30 日間)
Hamid
Hamid 2022 年 8 月 5 日
コメント済み: Hamid 2022 年 8 月 10 日
Dear experts,
I have 3 loops as shown in the code and want to find elements of t_p but the hmd variable is empty and not filling correctly.
When I use commad window and for example set (i=10,j=10,k=10) the command works and the desired values are obtained.
The purpose of my code is to find the values for t_p that are within a specefic x,y,z range.
Many Thanks in advance.
p = readtable ('pnts.txt');
p = table2array(p);
x_p=p(:,2);
y_p=p(:,3);
z_p=p(:,4);
t_p=p(:,5);
xedges=-100:10:100;
yedges=-100:10:100;
zedges=0:10:200;
for i = 1:length(xedges)-1
for j = 1:length(yedges)-1
for k = 1:length(zedges)-1
hmd = t_p((xedges(i)<= x_p) & (x_p < xedges(i+1)) & ((yedges(j)<= y_p) & (y_p < yedges(j+1))) & ((zedges(k)<= z_p) & (z_p < zedges(k+1))));
end
end
end

採用された回答

VBBV
VBBV 2022 年 8 月 6 日
編集済み: VBBV 2022 年 8 月 6 日
p = readtable ('pnts.txt');
p = table2array(p);
x_p=p(:,2);
y_p=p(:,3);
z_p=p(:,4);
t_p=p(:,5);
xedges=-100:10:100;
yedges=-100:10:100;
zedges=0:10:200;
for i = 1:length(xedges)-1
for j = 1:length(yedges)-1
for k = 1:length(zedges)-1
hmd = t_p((xedges(i)>= x_p) & (x_p <= xedges(i+1)) & ((yedges(j)>= y_p) & (y_p <= yedges(j+1))) & ((zedges(k)>= z_p & (z_p) <= zedges(k+1))));
end
end
end
hmd
hmd = 6109×1
0.1449 0.0674 2.0756 0.0145 0.0492 0.0313 0.6017 0.0109 0.0477 0.0680
According to condition given inside the for loop the number of points will vary, It appears for this data, it is 6109x1 matrix
  1 件のコメント
Hamid
Hamid 2022 年 8 月 10 日
@VBBV Thank you so much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by