Store a values in to a table at each iteration of loop
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Create a table to store the computed values with each itreation of a loop.
With reference to the given code, I want to store the labeled values of f1,f2,f3 in to a table with each iteration of loop
clear all
close all
v1=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
Fs=12000; %sampling frequency
T=1/Fs; %sampling period
L=length(v1); %Lenght of the signal
t=((0:L-1)*T)';
requiredLength=5;
requiredArray3 = [];
frequencyArray = [];
freq = ((1:5)*Fs/5);
%loop
for n = v1
requiredArray3 = [requiredArray3, n];
if numel(requiredArray3) == requiredLength
fastFourier = fft(requiredArray3);
A = fastFourier(:,1:3);
B = freq(:,1:3);
f1 = sum(B.*A)/sum(A);
f2 = sum(requiredLength - f1)/requiredLength;
f3 = sum(sqrt(B-f1).*A)/requiredLength.*sqrt(f2);
requiredArray3 = [];
end
end
0 Kommentare
Antworten (1)
VBBV
am 20 Okt. 2022
clear all
close all
v1=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
Fs=12000; %sampling frequency
T=1/Fs; %sampling period
L=length(v1); %Lenght of the signal
t=((0:L-1)*T)';
requiredLength=5;
requiredArray3 = [];
frequencyArray = [];
freq = ((1:5)*Fs/5);
%loop
for n = 1:length(v1)
requiredArray3 = [requiredArray3, n];
if numel(requiredArray3) == requiredLength
fastFourier = fft(requiredArray3);
A = fastFourier(:,1:3);
B = freq(:,1:3);
f1(n) = sum(B.*A)/sum(A);
f2(n) = sum(requiredLength - f1(n))/requiredLength;
f3(n) = sum(sqrt(B-f1(n)).*A)/requiredLength.*sqrt(f2(n));
requiredArray3 = [];
end
end
f1
f2
f3
3 Kommentare
VBBV
am 20 Okt. 2022
clear all
close all
v1=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
Fs=12000; %sampling frequency
T=1/Fs; %sampling period
L=length(v1); %Lenght of the signal
t=((0:L-1)*T)';
requiredLength=5;
requiredArray3 = [];
frequencyArray = [];
freq = ((1:5)*Fs/5);
%loop
for n = 1:length(v1)
requiredArray3 = [requiredArray3, n];
if numel(requiredArray3) == requiredLength
fastFourier = fft(requiredArray3);
A = fastFourier(:,1:3);
B = freq(:,1:3);
f1(n) = sum(B.*A)/sum(A);
f2(n) = sum(requiredLength - f1(n))/requiredLength;
f3(n) = sum(sqrt(B-f1(n)).*A)/requiredLength.*sqrt(f2(n));
requiredArray3 = [];
end
end
T = table(abs(f1).',abs(f2).',abs(f3).','VariableNames',{'f1','f2','f3'})
VBBV
am 20 Okt. 2022
If you want to store every 5 element, then use
f1 = f1(1:4:end)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!