How to populate array with column vectors of different lengths

2 次查看(过去 30 天)
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!

回答(1 个)

the cyclist
the cyclist 2020-4-20
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 个评论
Erik Hopkins
Erik Hopkins 2020-4-20
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 2020-4-20
编辑:the cyclist 2020-4-20
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by