How can I plot multiple graphs from one set of table data, separated by NaN?
1 view (last 30 days)
Show older comments
I have a table as below: M=
NaN NaN
2 3
NaN NaN
NaN NaN
15 6
6 7
3 12
38 17
9 59
NaN NaN
10 129
11 34
9 5
NaN NaN
NaN NaN
NaN NaN
Goal: I am trying to plot graphs from each set of data, that is separated by the NaNs
E.g. for the data below a graph with x=2, y=3 Then a graph with x=15, 6, 3, 38, 9, y=6, 7, 12, 17, 59 respectively
Overall goal: to find the slope of each set of data and plot the slopes as a frequency distribution
Thank you!
0 Comments
Answers (3)
Raul Andres Lopez Romero
on 13 Dec 2017
You can do this,
first we need to do a logical index for the NaN values,
M= ... %(your data values);
M1=M(1:end,1)
M2=M(2:end,2)
The Index for logical values are (isnan, check documentation for more info)
idxsM1 = ~isnan(M1);
*|*so the index show this*|*
0
1
0
0
1
1
1
1
1
0
1
1
1
0
0
0
M1noNaN=M1(idxsM1)
so you can plot because all NaN values are not in the vector.
plot(M1noNaN)
hold on
plot(M1noNaN-detrend(M1noNaN))
% So detrend (a-detrend(a)) plot the mean value or, slope im not sure check documentation for more info hold off
if you want the vector of detrend sM1=detrend(M1noNaN)
Do the same for vector M2 or second column of you data set M
0 Comments
Raul Andres Lopez Romero
on 13 Dec 2017
Edited: Raul Andres Lopez Romero
on 13 Dec 2017
I think checking your update, you want something like this
the code for this its simple, you need to generate the second vector without NaNs and do a scatter plot
scatter(M1noNaN,M2noNaN,'filled')
grid on
xticks(0:1:40)
xtickangle(90)
yticks(0:5:140)
and you can check this for the slope
2 Comments
Raul Andres Lopez Romero
on 13 Dec 2017
Check the new answer, then, i think you can manage the data and do all the calculations that you need.
Raul Andres Lopez Romero
on 13 Dec 2017
Edited: Raul Andres Lopez Romero
on 13 Dec 2017
% Star with position and values
% A it's your matrix that contains the NaN elements
pos=[true,isnan(A(:,1)).',true];
ini=strfind(pos,[true, false]);
end=strfind(pos,[false, true]) - 1;
M=cell(1,length(ini));
for i = 1:length(ini)
M{i} = A(ini(i):end(i),:);
end
% That creates a M cell vector to contains all the values
% But for generate the M1 and M2 ... Mi vectors you need to transform
%the cell vector in array
M1=cell2mat(M(1,1))
% for M2
M2=cell2mat(M(1,2))
% for M3
M3=cell2mat(M(1,3))
the result is
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!