Assigning NaN to variables, inserting into a cellarray and then plotting Error

1 visualización (últimos 30 días)
Hello, I have a load of images of a spot that I loop through and find certain characteristics such as the centroid of the spot. However, sometimes there is a blank image (due to defocus) and hence to prevent my loop crashing, i use a try and catch and assign the centroid positions in the catch as:
x1=NaN; y1=NaN;
I have about 6 other columns of metrics too.
I Display these in a uitable, but because I want to control the decimal places, I have to convert my data to a cellarray. I do this via:
data=num2cell(data)
fun=@(x)sprintf('%0.2f',x);
data1=cellfun(fun,data,'UniformOutput',0);
app.UITable.Data=data1;
Which gives i my UITABLE:
{'1.00' } {'101.61'} {'102.12'} {'8.36' } {'8.70' } {'8.53' } {'1412.00'}
{'2.00' } {'100.01'} {'101.66'} {'8.38' } {'8.82' } {'8.60' } {'1456.00'}
{'3.00' } {'98.08' } {'101.21'} {'8.31' } {'8.61' } {'8.46' } {'1500.00'}
{'4.00' } {'99.91' } {'100.80'} {'8.44' } {'8.60' } {'8.52' } {'1466.00'}
{'5.00' } {'99.85' } {'100.84'} {'8.47' } {'8.74' } {'8.61' } {'1454.00'}
{'6.00' } {'100.16'} {'100.16'} {'8.71' } {'8.85' } {'8.78' } {'1430.00'}
{'7.00' } {'101.50'} {'99.50' } {'8.55' } {'8.96' } {'8.76' } {'1388.00'}
{'8.00' } {'100.08'} {'99.72' } {'8.80' } {'9.15' } {'8.97' } {'1396.00'}
{'9.00' } {'100.50'} {'99.00' } {'8.42' } {'8.86' } {'8.64' } {'1456.00'}
{'10.00'} {'100.74'} {'98.99' } {'8.45' } {'8.76' } {'8.60' } {'1437.00'}
{'11.00'} {'101.99'} {'98.25' } {'8.36' } {'8.83' } {'8.60' } {'1448.00'}
{'12.00'} {'NaN' } {'NaN' } {'NaN' } {'NaN' } {'NaN' } {'9.00' }
{'13.00'} {'101.75'} {'98.00' } {'8.39' } {'8.62' } {'8.51' } {'1487.00'}
So when I want to plot a graph of column 1 against say columns 2,3,4,5, without any NaNs I use
X=cell2mat(D(:,1));
Y2=cell2mat(D(:,2));
Y3=cell2mat(D(:,3));
Y4=cell2mat(D(:,4));
Y5=cell2mat(D(:,5));
and plot. However, when there are NaNs the cell2mat doesn't seem to work.
I have tried this but again it doesn't work:
out = D(any(cellfun(@(x)any(~isnan(x)),D),2),:)
X=cell2mat(out(:,1))
Y2=cell2mat(out(:,2))
any help is grately appreciated, thanks

Respuesta aceptada

Simon Chan
Simon Chan el 21 de En. de 2022
Suppose variable A is the data in your uitable. You may use function str2double
B = str2double(A);
Then plot it using B(:,1), B(:,2), etc

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by