Saving Answers as Matrix
4 次查看(过去 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!