help with maintaining order of values when removing NANs and converting matrix to column vector
Show older comments
Hi all, I have looked at a few questions/answers here for how to convert a matrix to column vector and how to remove NAN values from an array. What I would like to do is take some outputs of a finite element model I am running and plot values against each other in a scatter plot. The outputs are in the form of 201x201 double matrices. Using the following code I can acheive what I was hoping to do. My question, when I convert the matrix to column vector and remove the NAN values, are the values I am plotting against eachother located in the same place in the original matrix? The NAN values are in same place in each matrix. Is there a way to maintain the order of values when converting a matrix to column and then removing values? Is this the default way the action is performed? I have attached two matrices for consideration or example.
%start with stress
load("cora-01_micro_stress_griddata.mat");
%load 2nd invariant of stress plot
B=flipud(micro_stress{1,1,10});
%convert to dif stress
%dif=2*sqrt(2)*B;
%convert matrix to column vector
D=reshape(B,[],1);
%remove NAN values
D = D(~isnan(D));
%now strain rate
load("cora-01_micro_strain_griddata.mat");
%2nd invariant of strain rate
A=flipud(micro_strain{1,1,9});
%convert matrix to column vector
C=reshape(A,[],1);
%remove NAN values
C = C(~isnan(C));
%scatter stress over strain rate
figure(1);
scatter(log10(C),D);
set(gca,'XDir','reverse');
title('2nd Invariant of Stress over Strain Rate')
xlabel('Log10(2nd invariant of strain rate)');
ylabel('2nd Invariant of Stress MPa');
1 Comment
Stephen23
on 7 May 2025
Why do you need to remove the NaN values?
Accepted Answer
More Answers (0)
Categories
Find more on Stress and Strain 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!

