plotting data that includes '-nan(incl)'
Mostra commenti meno recenti
Hi,
I have been gathering Data for experiments via .CSV files.
If the laser in the experiment is too far from a detector, the measurement at that time would, understandably, provide a 'nan'.
However, if this occurs, a function i wrote to convert .CSV data into arrays of doubles stops working, instead, it returns cells. I cannot plot these cells.
I guess the issue i am having is telling matlab to replace thoses nans with an arbitrarily large number or completely remove them and then provide me with a plottable Double array.
The Following Code contains: Csv2array function + 1 set of data plotting as expected + 1 set of data returning a cell type array rather than double:
clear all, clc, close all
%Mechanical Turbulance (Random) (Works as expected)
%T5
%Load data CSV
[T5nct, T5ncx1, T5ncy1, T5ncI1] = CSV2array("LF_BS_NC_Turb1.csv");
[T5ct, T5cx1, T5cy1, T5cI1] = CSV2array("LF_BS_C_Turb1.csv");
figure %Look at it
subplot(211)
plot(T5nct,T5ncx1, T5nct, T5ncy1, T5ct, T5cx1, T5ct, T5cy1)
legend({'NCx1(um)', 'NCy1(um)', 'Cx1(um)', 'Cy1(um)'}, 'location', "best")
title('Test 5: Random Turbulance, No Correction Vs Correction (x,y)')
xlabel('Time (seconds)');
ylabel('Distance From Centre (microns)');grid on, grid minor;
subplot(212)
plot(T5nct,T5ncI1, T5ct, T5cI1)
legend({'(NC)Intensity(Volts)', '(C)Intensity(Volts)'}, 'location', "best")
title('Test 5 (I(V))')
xlabel('Time (seconds)');
ylabel('Intensity (Volts)');
grid on, grid minor;
%T6: NC -> C in 2mins, random mechanical adjustment of FSM (Does not work
%as expected
%Load data CSV
[T6t, T6x1c, T6y1c, T6I1] = CSV2array("LF_BS_NC+CT6.csv");
%Matlab having a hissy fit, decides to convert to cell instead
T6x1=cell2num(T6x1c);
T6y1=cell2num(T6y1c);
figure %Look at it
subplot(211)
plot(T6t, T6x1, T6t, T6y1)
legend({'x1(um)', 'y1(um)'}, 'location', "best")
title('Test 6: Random Turbulance, No Correction Vs Correction (x,y)')
xlabel('Time (seconds)');
ylabel('Distance From Centre (microns)');grid on, grid minor;
subplot(212)
plot(T6t,T6I1)
legend({'(NC)Intensity(Volts)', '(C)Intensity(Volts)'}, 'location', "best")
title('Test 6 (I(V))')
xlabel('Time (seconds)');
ylabel('Intensity (Volts)');grid on, grid minor;
function [t, x, y, I] = CSV2array(CSV)
TableData = readtable(CSV); %Puts CSV into table
%separate into columns of interest
tt= TableData(:,1);
xt= TableData(:,2);
yt= TableData(:,3);
It= TableData(:,4);
%Turns each table into an array
t= table2array(tt)./1e3; %converts time to Seconds
x= table2array(xt);
y= table2array(yt);
I= table2array(It);
end
Error: Error using plot
Invalid data argument. (When trying to plot the cell array)
Blank plot when trying to use "cell2num"
I have tried many other things but these are rather convoluted in my head and i fear it would be rather lengthy and useless to try and find everything I have tried so i can list to you.
I hope everything has been layed out clearly,
Thanks
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Data Type Conversion in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

