How can i plot a continuous graph with NaN in matlab?

16 views (last 30 days)
I have an array of data as below:
1.0e+03 *
-0.0001 0.0033 0.0002 0.0000
NaN NaN NaN NaN
0.0032 0 NaN NaN
0.0033 0.0067 0.0002 0.0000
NaN NaN NaN NaN
0.0099 0 NaN NaN
0.0099 0.0067 0.0002 0.0000
NaN NaN NaN NaN
0.0165 0 NaN NaN
0.0166 0.0066 0.0001 0.0001
0.0232 0 NaN NaN
0.0232 0.0066 0.0001 0.0001
0.0298 0 NaN NaN
0.0299 0.0002 0.0001 0.0001
0.0300 0.0007 0.0001 0.0001
0.0307 0.0006 0.0001 0.0001
0.0319 0.0033 0.0001 0.0001
0.0352 0 NaN NaN
0.0352 0.0066 0.0001 0.0001
0.0418 0 NaN NaN
0.0419 0.0066 0.0001 0.0001
0.0485 0 NaN NaN
0.0485 0.0067 0.0002 0.0000
NaN NaN NaN NaN
0.0551 0 NaN NaN
I want to plot as follow:
subplot(2,1,1), plot(A(:,1),A(:,3));
subplot(2,1,2), plot(A(:,1),A(:,4));
The goal is to replace the NaN with the previous value. any help will be highly appreciated, thanks.

Answers (1)

Thorsten
Thorsten on 15 Jul 2016
x = sum(mat, 2);
A = mat(~isnan(x), :);
subplot(2,1,1), plot(A(:,1),A(:,3));
subplot(2,1,2), plot(A(:,1),A(:,4));

Products

Community Treasure Hunt

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

Start Hunting!