Save each output step in rows in a larger matrix
1 次查看(过去 30 天)
显示 更早的评论
From the below code I get k number of Q1. I am trying to save each of the Q1 in Row1, Row2, Row3..... Rowk. I have been doing the same for the i and j loop but for some reason its failing when I apply the same thing for the Q1. I appreciate any suggestion.
clc
clear all
S = dir('F.*');
for k = 1:numel(S)
S(k).name;
T = dir('Na-XYZ.*');
for k = 1:numel(T)
T(k).name;
Nadump = dlmread(T(k).name, ' ', 9, 0);
Fdump = dlmread(S(k).name, ' ', 9, 0);
L1 = length(Nadump);
L2 = length(Fdump);
for i=1:L1
for j=1:L2
X(i)= sqrt((Fdump(j,3)-Nadump(i,3))^2 + (Fdump(j,4)-Nadump(i,4))^2 + (Fdump(j,5)-Nadump(i,5))^2);
X(i) = X(i)/10;
Y(j,i) = sort(X(i));
end
end
Y1 = Y';
Y2 = sort(Y1);
S1= sort ((Y2(1,:))');
ind1 = S1(:,1) < .28;
ind2 = S1(:,1) < .55;
ind3 = S1(:,1) < .79;
A1 = S1(ind1,:);
A2 = S1(ind2,:);
A3 = S1(ind3,:);
Q1 = [length(A1), (length(A2)-length(A1)), length(A3)-length(A2), 125-length(A3)];
end
end
0 个评论
采纳的回答
Jon
2022-1-7
编辑:Jon
2022-1-7
You have a number of problems with your code.
The main problem, if you want to save the results of each iteration in variable Q, then the left hand side of Q needs to have an ndex specified. Otherwise you are just writing over the value of Q with each iterartion. So you need something like
Q(k,:) = length(A1), (length(A2)-length(A1)), length(A3)-length(A2), 125-length(A3)];
where k is the index of your for loop.
Now another problem that you have is that you have two nested for loops, both using the same index variable, k.
This doesn't make any sense. If you have two nested loops then they each need their own index.
So for example
for k = 1:numel(S)
S(k).name;
T = dir('Na-XYZ.*');
end
for m = 1:numel(T)
.
.
.
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!