Store a values in to a table at each iteration of loop
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
VBBV
2022-10-20
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 个评论
VBBV
2022-10-20
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'})
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!