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!