How to populate array with column vectors of different lengths

2 Ansichten (letzte 30 Tage)
Erik Hopkins
Erik Hopkins am 20 Apr. 2020
Bearbeitet: the cyclist am 20 Apr. 2020
I have an 8635x9 array of AFM data, ind_F, where each column is an indentation force curve. I'm having two major problems with the data set:
1) plot(Ind_F) will plot the 9 indentations but each trace begins increasing at different X values (see first attached graph).
I would like to align all the traces such that they start increasing at the same X value. I think I solved this with a for loop that recognizes the X index where the trace crosses a set threshold, cut, and plots from there, but I feel there's a more efficent way to do this.
cut = 2*10^-10; %set threshold to determine where curve starts
spacer = 500; %spacer from Y axis
for i = 1:size(ind_F,2)
ind_F_logical = ind_F > cut;
[i_upstart i_trace] = find(ind_F_logical(:,i),1,'first'); %find X index where trace crosses threshold
hold on
plot(ind_F(i_upstart-spacer:end, i));
hold off
end
2) I also want an array with these aligned trace values but each vector will be a different length. I was thinking of elongating shorter vectors with NaNs but cant figure out howt to do that.
Thanks!
  2 Kommentare
the cyclist
the cyclist am 20 Apr. 2020
Can you upload your data in a MAT file (using the paper-clip icon)?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

the cyclist
the cyclist am 20 Apr. 2020
I think this does what you want, in a slightly less complicated way:
figure
hold on
for i = 1:size(ind_F,2)
plot(ind_F(ind_F(:,i)>=cut,i))
end
(I didn't add in the "spacer".)
  2 Kommentare
Erik Hopkins
Erik Hopkins am 20 Apr. 2020
yes, thanks. This does it in a much simpler way. I'm still stuck on creating a new array with these aligned traces however
the cyclist
the cyclist am 20 Apr. 2020
Bearbeitet: the cyclist am 20 Apr. 2020
new_ind_F = nan(size(ind_F));
figure
hold on
for i = 1:size(ind_F,2)
this_vec = ind_F(ind_F(:,i)>=cut,i);
new_ind_F(1:size(this_vec),i) = this_vec;
end
plot(new_ind_F)
Still a little awkward, but it gets the job done.
Note that you can extract the plotting from the for loop this way, but might be more intuitive leaving it in the loop.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB 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