Effacer les filtres
Effacer les filtres

Saving Answers as Matrix

2 vues (au cours des 30 derniers jours)
Nihar Jariwala
Nihar Jariwala le 25 Mar 2021
Commenté : Rik le 25 Mar 2021
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

Réponses (1)

DGM
DGM le 25 Mar 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 commentaires
Nihar Jariwala
Nihar Jariwala le 25 Mar 2021
Hey,
Yes, I wrote this code.
I simply want to save duration, thats it
I want to do is:
When it runs in a for loop:
ans = %From File 1
1
2
3
ans = %From File 2
4
5
6
I simply want it as & also saved as;
Filename = %Duration =
1
2
3
4
5
6
Rik
Rik le 25 Mar 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by