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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by