Saving Answers as Matrix
Mostrar comentarios más antiguos
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
Respuestas (1)
DGM
el 25 de Mzo. de 2021
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 comentarios
Nihar Jariwala
el 25 de Mzo. de 2021
DGM
el 25 de Mzo. de 2021
You want to save them "one below another" but not concatenate them? What exactly are you trying to do? Your question is ambiguous. I can't guess which arrays you're trying to "save" and I can't guess what you want to do with them.
Did you write this code?
Nihar Jariwala
el 25 de Mzo. de 2021
Rik
el 25 de Mzo. de 2021
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.
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!