store data in an array

13 vues (au cours des 30 derniers jours)
ignacio bobadilla tapia
ignacio bobadilla tapia le 3 Juin 2021
Commenté : Walter Roberson le 4 Juin 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

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by