Saving Answers as Matrix
2 ビュー (過去 30 日間)
古いコメントを表示
Hi Guys,
I am running a for loop for files, The files are something like this:
ans=
1
2
3
4
5
ans=
4
5
6
2
4
4
68
92
983
I want to combine all the above answers that I got after running the for loop like this:
Final Answer =
1
2
3
4
5
4
5
6
2
4
4
68
92
983
clc
clear all
close all
%Sampling Frequency Hz%
Fs = 1650;
%Sampling Time (seconds)
Ts = 120;
%One Readinh
T = 1/Fs;
foldertoe = dir('12LPS_G_Fr5.42_X=0_Y=*');
ntoe = length(foldertoe);
for itoe = 1:ntoe
load(foldertoe(itoe).name);
LeadingTip = logical(voltageA>2.5);
Ns = find( LeadingTip(1:end-1)& ~LeadingTip(2:end));
Ne = find( ~LeadingTip(1:end-1)& LeadingTip(2:end));
%Converting the Arrays into one when not of the same size.
sx = size(Ns);
sy = size(Ne);
a = max(sx(1),sy(1));
z =[[Ns;zeros(abs([a,0]-sx))],[Ne;zeros(abs([a,0]-sy))]];
Duration = abs((z(:,2)-z(:,1)))*T%Bubble Duration%
h = histogram(Duration,[0:0.005:0.2],'Normalization','Probability');
area = sum(h.Values)
end
0 件のコメント
回答 (1 件)
DGM
2021 年 3 月 25 日
You just want to concatenate the arrays? I'm guessing the outputs are Duration and area. You can do that like this:
% concatenate along dim 1
finalanswer=cat(1,Duration,area);
alternatively,
% or you can do the same thing more succinctly
finalanswer=[Duration; area];
4 件のコメント
Rik
2021 年 3 月 25 日
It is probably as simple as
Duration=cell(ntoe,1);
for itoe = 1:ntoe
%your other code
Duration{itoe} = abs((z(:,2)-z(:,1)))*T; %Bubble Duration%
end
Duration=cell2mat(Duration);
Did you do a basic Matlab tutorial? And why are you using clear all? Or close all? You could also reboot your computer between every run of the script instead.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!