Convert 190x1 cell array into scatter plot?

I have a 190x1 cell array and each cell contains {131x1}. The 190 represents the number of time points or what I want listed as my x-axis. Then each cell contains 131 data points that I want to be my y value for each x-axis value. I can figure out how to get the y values, but unable to figure out how to get the corresponding x-value. I'm sure there is a simple explanation, but i haven't been able to find it through the mathworks website!
x=??
y=cell2mat(data(:))
scatter(x,y)
Thank you so much!

Risposte (1)

% Data: 190x1 cell array and each cell contains {131x1}.
ncells = 20;
npoints = 50;
for i=1:ncells
data{i, 1} = randn(npoints, 1);
end
x=1:npoints;
y=cell2mat(data'); % assume data is ncells x 1
scatter(x,y)

3 Commenti

Thank you for answering my question.. I still don't seem to be able to get it to work though :(
Here is what I have:
% Data: 190x1 cell array and each cell contains {131x1}.
Data = 190x cell array with each cell contains {131x1}
ncells = 131;
npoints = 190;
x=1:npoints;
y=cell2mat(data'); % assume data is ncells x 1
scatter(x,y)
x variable is a 1x190 array
y variable is 131x 190 array
and I keep on getting the error that x and y must be vectors of the same length.
Chunru
Chunru il 1 Set 2021
Modificato: Chunru il 1 Set 2021
You have to show what data you have. It looks like your cell array is 1 x ncells instead of ncells x 1. Each cell is 1x190 instead of 190 x 1. Therefore, you can plot the data:
scatter(x, y')
hmm yeah I was unable to get that method to work.
However I used your "y=cell2mat(data')" part
to figure out something else
so I made
x=1:190 (or 1 x 190 array)
but made this into an repetitive array so it matched the y data which was 131 x 190
so with both matrixes 131 x 190 I turned them back into vectors to finally produce the scatter (x,y)!

Accedi per commentare.

Prodotti

Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by