Plotting a cellArray Issue

Hello,
I have a cellarray thats for example: cellArray = {1X8}; and each cell is 1X1023. But im having issues plotting this. Ive tried cell2mat. But this just returns a giant char array:
c = '205020502049205020512051205120............'
I tried seperating every 4 chars and plotting but failed. Im trying to read values from a arduino serial port from one of its analog inputs. Ive tried cellfun(@plot,cellArray); and plot(cellArray{1,1}); but get invalid first argument errors.....at a bit of a loss, and I know its a simple solution just stuck.

3 Comments

Your data seems to be in a char format. Can you provide a small example of your data? You could also attach the entire array in a mat file.
And what exactly is your desired output?
hFig = figure('Name',datestr(now),'units','normalized','Color',[0,0,0],...
'MenuBar','none','DockControls','on');
hAxes1 = subplot(2,2,1);
hAxes2 = subplot(2,2,2);
hPlot1 = plot(hAxes1,NaN,NaN);
assignin('base','hPlot1',hPlot1);
s = serial('COM9');
arrSize = 1;
fopen(s);
j = 1;
Fs=100000;
i = 1;
buffFatman = 1024;
bufferFatman = nan(1,buffFatman);
x = [];
y = [];
celldata2 = [];
z = 0;
while j <= 1024
if (j==1024)
%if 1024 values have been reached increment z and store in
%cell array
z = z + 1;
% temp = bufferFatman';
% celldata2{z} = celldata;assignin('base','celldata(j)',celldata(j));
%plot celldata(i) and then increment
% set(hPlot1, 'Xdata',1:1-1/Fs:buffFatman,'Ydata',celldata2{1,j});
j = 1;
arrSize = arrSize + 1;
% disp(arrSize);
%cell2mat function; A = cell2mat(C);
celldata2{z} = celldata;
% A = cell2mat(celldata2{2});
A = cell2mat(celldata2{1,j});
assignin('base','A',A);
assignin('base','celldata2',celldata2);
pause(0.01);
i = i + 1;
end
x = fscanf(s);
pause(0.01);
celldata(j) = cellstr(x);
assignin('base','celldata',celldata);
% cellfun(@plot,MyCell);
j = j + 1;
%after obataing data,store it in buffer and display it
end
%DATA...NOT PART OF CODE
celldata2 = 1x1023 cell 1x1023 cell 1x1023 cell 1x1023 cell 1x1023 cell 1x1023 cell
%if I use cell2mat as such c = cell2mat(celldata2{1,1});
c = '205020502049205020512051205120502050204820502050205020512050205020492051205020502051204920502048205020502051205020502049205120502051205020502049205120502050204920512051205020502051205020492050204920492048205120512051205020482049205020502051204920512051205020482049205020502050205020492050205020512050205020502050205020502049205120492050205020512050205120502051204920512051205020502049205220502052204920512048205120512049205020492051205120502050204920502050204920502051204920502049205020512050205020512050204920492049205120502050205120492051204920502049204920502049204920492049205020492051205020492048205020492050205120502050205120512049204920492050205020502050204920492050205120492051204920512051205020502049204920492050205120502051205020512052205020502049204920492051205020512050205020492050205020502050205120502050205020492049205020502051204920512051205020492050205020502049205120522051205020492049204920502050205120502050205020502051205020502049205020502050205020502051204920502049205020492050205220502049204920502052205120502050204920512051205120502050205020502050205020492051205020512050205020502051205020502051204920502049205020512050205020492051205120512050204920492049205120502052205020502050205120502050204820492050205020502050205020492050204920492050205020502051205020502049205020502051205020502050205120502051204920512050205020502050204920492050205120502050205020492049205120512052205120502049204920492051205120502050205120512049205020502051204820502051205020492049204920502050205120502050205020492050205020512050204920512050205020512051205020502050204820492051205020492049205020502050204920512051204920502051204920512050205120502051205120502052205120522051204920492051205020512049205120492050205120502051205120502051205020512048205120492051205020502049205120502051204920502049205020512050205020512050204920512049205020502050205020502050205020502049205120502050204920502050204920492051205120502049204920492050204920502050205020492049205020492049204820512049205120512049205020512051205020482049205120512049204920492051204920512050205020502049205020482050204920512049204920502051204920502049205220512051204920502049205120502050205220502049205020492051205020492052205020502050205020512051204920502050205120492051205020502050205020502049205020492050204920502050205120512051204920512050205020502050204920512050205020513204920512050205120512050204920512051205020502051205120512050205020502049205220512051205020512049205020492051204920502050205020512050205020482048205020502051204920502050205020492051204920502050205120502051204920502050204920512049204920502050205120492050205020512049204920492050205120512050205020502051205020502050205120522050204920492049205120512051204920502050205020492050204920502050205020502051205020512048205020502051204920512051205120492050205020512049205020492049205120512050204920492051205020522049205120502050205020512049205020492051205120502050204820502050205120492050205020502051205120492050204920512051205120502051204920512050204920502050205220492050205020502051205020502050204920492051205120492050205020522051205120512052205120492050205120502049205120512050205020502050205120492051205020502050205020502051205020502050205120512049205020502051205020492048205020502050205020492049205120502051205020502050205020502048205120492050204820502050205120502049205020502050205120502049205020512051204920502052205020502049205120492049205020492051205120512051204920492049204920512050205020512050205020512050204820502050205020512051205020512050205020502051205120492050205020502050205120492050204920502050205020502050205020502050205120502051204920502049205020512050204920502050205020502050205020502050205120502051204920502051204820502049205120492051205020512050205120502050205020512049205020502051204920512049205020512051205020502050205020502050205120512050204920492051205020502050205120502050204920492050205020502050204820502050205020492050204920512050205020502050205120502049205120502050204920502051205020502049205020502050205020502050205020502049205020512050205020492051205020502049205020502051205120512049205020502050205120502051205020492048205020512051204920512050'
My desired output is to plot the data in realtime but using hPlot1 and updating the X,Y data, but
im having issues just doing a 1 time plot that displays 1 certain set of time that doesnt update itself.And apologies about the code, I know theres some useless variables and comments,but ive just been getting frusterated with this lol,apologies.
Why are you using assignin? And how can the while loop exit?

Sign in to comment.

 Accepted Answer

Raghunandan V
Raghunandan V on 28 May 2019
Hi m j,
Can you try something like this?
celldata(j) = str2num(x)
By doing this you are just storing them as numbers but not as str cell. and you can easily plot.

3 Comments

You should use str2double instead.
The values from arduino COM port is always int :)
If you are getting only a single value it is safer to use str2double (which avoids a call to eval and is therefore not vulnerable to function call injects). A cast to char avoids input type issues.
x=uint8('75');
x=str2double(char(x));

Sign in to comment.

More Answers (0)

Categories

Asked:

m j
on 27 May 2019

Commented:

Rik
on 28 May 2019

Community Treasure Hunt

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

Start Hunting!