store data in an array

10 Ansichten (letzte 30 Tage)
ignacio bobadilla tapia
ignacio bobadilla tapia am 3 Jun. 2021
Kommentiert: Walter Roberson am 4 Jun. 2021
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 3 Jun. 2021
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 Kommentare
ignacio bobadilla tapia
ignacio bobadilla tapia am 3 Jun. 2021
It executes the code, but I get an empty set in the results of the code.
Walter Roberson
Walter Roberson am 4 Jun. 2021
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by