Is not there a way to erase all the NaNs from a mxn matrix once and left the index values empty ?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Gulsen Gork
el 29 de Mzo. de 2021
Comentada: Adam Danz
el 30 de Mzo. de 2021
Hi everyone,
I have a set of data that was recorded by Labview.
The data is recorded in sets of two columns :
(Int: Intensity of data and it is recorded in even-numbered columns), (nonZ: non-normalized Z data which is recorded in odd-numbered columns).
This data belongs to a Z-scan NLO measurement so the data Intensity starts with constant and drastically decreases @z=0 and goes to a minimum of Intensity, thus the point z=0 is the focal point. I need to find the minimum value of Intensity and its corresponding index for each column, then using this index (z-point) I have to rearrange the z-values. So the Z-values will be turn from (0, 10, 20, 30...... .. ) to (...-20 -10 0 10 20....) etc.
*** I separated code sections and tried to explain all steps one by one.
Sec#1: Read the data file and extract the values from Intensity and Z- rows.
Sec#2: Each Intensity- nonZ duo belongs to different measurements and in each data set there is one minimum point for Intensity. Due to this point, the z values need to be rearranged. So I tried to find the indexes of these mins.
Sec#3: Another point is that the columns of each measurement are different, which means in each measurement the number of recorded data points may vary. And that results in NaN values inside the matrix nonZ. I tried to get rit of these NaNs.
Sec#4: After sec#3 I have to turn nonZ array into the mxn matrix (the dimensions should be the same with the matrix Intensity). Then I will rearrange the z-values due to the min of Intensity(using the index of Intensity min). I had used a very similar code for a very long time, but now the shape of the input data has changed so I am arranging the code again. I am confused while erasing the NaN values from a matrix. Is not there a way all the NaNs from a mxn matrix once and left the index values empty.
**There may be a way to divide the nonZ array using the first value in each measurement (0.6250). Because the z- values are automatically created by Labview code they all start with 0.6250. I tried to divide all nonZ array using this specific value, but I guess I did sth wrong.
After this point I could not decide what to do, I could not get a usable form for nonZ matrix. I know how to rearrange the z-values due to min of Intensity but my z-values are not usable now.
NOT: I am attaching the data values, I hope you can give some advice.
Thanks for all.
%SEC#1:......................................................
inputFile = 'xxx_data';
data1 = xlsread([ inputFile '.xls' ]);
minler=[];
Int=[];
nonZ=[];
%All INTENSITY values
for ii=1:width(data1)/2
Int(:,ii)=data1(:,ii*2);
end
%All nonnormalized Z values
for ii=1:width(data1)/2
nonZ(:,ii)=data1(:,ii*2-1);
end
%.............................................................
%SEC#2:......................................................
for j=1:length(Int(1,:))
for i=1:length(Int(:,1))
nummin=min(Int(:,j));
[yminn1,xminn1]=ind2sub(size(Int),find(Int(:,j)==nummin));
end
minler(1,j)=yminn1;
end
minler=minler';
%minler: These are the indexes of minimum of Intensity data for each measurement.
%..............................................................
%SEC#3:......................................................
%Erases NaNs in z column;
Int(isnan(Int))=10000;
C = isnan(nonZ);
Z_col = nonZ(~C);
%I got rid of NaNs but the matrix turn to be a M x 1 because of isnan!.
%......................................................................
%SEC#4:.................................................................
% divide Z_col into pieces due to 0.625 This value is the first value of z in
% each separate measurement.
for i=1:length(Z_col)
I(1,:)=find(Z_col==0.625) ;
if i>length(Z_col)
end
end
0 comentarios
Respuesta aceptada
John D'Errico
el 29 de Mzo. de 2021
A matrix cannot have "empty" elements. Well, a cell array can, or if you wrote a completely new class of your own, but standard matrices cannot do so. Matrices are recangular things, lacking any holes or missing values. In fact, NaNs are as close to a missing value you can have.
3 comentarios
Adam Danz
el 30 de Mzo. de 2021
Many Matlab functions have built-in options to ignore nans. For example,
a =[1 2 3 nan nan 6 7 nan 9 nan];
sum(a,'omitnan')
You can identify nans using
isnan(a)
For example,
a(isnan(a)) = -9999
And then there are functions like fillmissing that may come in handy in some cases.
Más respuestas (0)
Ver también
Categorías
Más información sobre Performance and Memory en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!