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'})
VBBV
2022 年 10 月 20 日
If you want to store every 5 element, then use
f1 = f1(1:4:end)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!