Info

此问题已关闭。 请重新打开它进行编辑或回答。

Output of For-loop in 1 file

1 次查看(过去 30 天)
Sam
Sam 2014-12-19
关闭: MATLAB Answer Bot 2021-8-20
I have a for-loop for 5 measurements. The first time it runs I get the output for the first measurement. The second time it runs, I get the output for the second measurement. But the output for the first measurement disappears. I know I need to save, but I want to see all the outputdata into 1 file. In 5 columns next to each other. How do I do this?
for i_testen=1:length(data_stair_rise)
RANK = data_stair_rise(1,i_testen).VideoSignals(:, strcmp('RANK', data_stair_rise(1, i_testen).VideoSignals_headers))
RANK = abs(RANK)
figure;
plot(RANK, 'g', 'LineWidth', 2);
ylabel('Distance');
xlabel('Datapoint');
title('Walking stairs', 'FontSize', 16);
legend({'Right ankle'})
xy = ginput(2);
xy(1,1) = 0;
Afstand_1schrede = xy(2,2)-xy(1,2);}
end
I want to save 'Afstand_1schrede' in 1 file with five columns (representing the 5 measurements op 1 subject).

回答(1 个)

Geoff Hayes
Geoff Hayes 2014-12-19
编辑:Geoff Hayes 2014-12-20
Sam - you need to use Afstand_1schrede as an array rather than a scalar. Try the following
% create the 1x5 array
Afstand_1schrede = zeros(1,length(data_stair_rise));
for i_testen=1:length(data_stair_rise)
% etc.
% save the measurement
Afstand_1schrede(1,i_testen) = xy(2,2)-xy(1,2);
end
  2 个评论
Sam
Sam 2014-12-19
Thanks for your answer, but Matlab gives the following error:
"Subscript indices must either be real positive integers or logicals."
Geoff Hayes
Geoff Hayes 2014-12-20
My mistake, should be i_testen instead of i in the update to the array.

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by