store data in an array

10 ビュー (過去 30 日間)
ignacio bobadilla tapia
ignacio bobadilla tapia 2021 年 6 月 3 日
コメント済み: Walter Roberson 2021 年 6 月 4 日
Along with saying hello, I need help storing information. I did a for loop so that it was storing data, but when dt = [] is not stored, also if you could help me that when it happens that dt = [], the threshold value is 1.5, it would be 0 and thus not have the error that dt was an empty set, in short, that when dt = [], the threshold is 0 so that I can calculate the loop and also store it in the dt matrix.
Thanks greetings.
I attach .txt with the data, a function and the code I leave it copied in the questions panel.
close all, clear all, clc
amplitude=load('amplitude.txt');
x=0:10:4*3600;
threshold = 1.5;
for j=1:7
y=amplitude(:,j);
[val,ind] = max(y);
x_peak = x(ind);
[t0_pos,s0_pos,t0_neg,s0_neg]= crossing_V7(y,x,threshold,'linear');
[minValue, closestIndex1] = min(abs(t0_pos - x_peak));
closestValue_pos = t0_pos(closestIndex1);
[minValue, closestIndex2] = min(abs(t0_neg - x_peak));
closestValue_neg = t0_neg(closestIndex2);
dt = abs(closestValue_neg - closestValue_pos)./60
end

採用された回答

Walter Roberson
Walter Roberson 2021 年 6 月 3 日
amplitude=load('amplitude.txt');
x=0:10:4*3600;
threshold = 1.5;
cols = size(amplitude,2);
all_dt = zeros(1,cols);
for j=1:cols
y=amplitude(:,j);
[val,ind] = max(y);
x_peak = x(ind);
[t0_pos,s0_pos,t0_neg,s0_neg]= crossing_V7(y,x,threshold,'linear');
[minValue, closestIndex1] = min(abs(t0_pos - x_peak));
closestValue_pos = t0_pos(closestIndex1);
[minValue, closestIndex2] = min(abs(t0_neg - x_peak));
closestValue_neg = t0_neg(closestIndex2);
dt = abs(closestValue_neg - closestValue_pos)./60;
if isempty(dt); dt = 0; end
all_dt(j) = dt;
end
  4 件のコメント
ignacio bobadilla tapia
ignacio bobadilla tapia 2021 年 6 月 3 日
It executes the code, but I get an empty set in the results of the code.
Walter Roberson
Walter Roberson 2021 年 6 月 4 日
The only way that code can return empty is if the loaded amplitude is empty. In such a case,, cols would come out as 0 and all_dt would be a 1 x 0 matrix.
In all other cases, the result in all_dt could potentially turn out all 0, but cannot turn out empty.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by