How to scatter plot a cell array

조회 수: 2 (최근 30일)
Weihao Fan
Weihao Fan 2020년 2월 10일
답변: Weihao Fan 2020년 2월 12일
I have a 1x18 cell array like the picture. The indices of the cells (1:18) represent the depths of my system. And each depth includes corresponding amount of data (for example, the 1st depth has 529 data). Now I want to plot these data as a function of depth. How can I achieve that? Should I use scatter function? But scatter function requires the length of x, y dimension to be same.
  댓글 수: 3
Adam Danz
Adam Danz 2020년 2월 11일
Weihao Fan's answer moved here as a comment.
Yeah that is my goal. And what do you mean by explaining the correspondence between depths
Adam Danz
Adam Danz 2020년 2월 11일
편집: Adam Danz 2020년 2월 12일
" what do you mean by explaining the correspondence between depths"
As you can see in the demo in my answer, each stack of dots has a different number of dots. So, if you expected to see trend lines connecting the dots between x values, you'd need to explain how those values are related since there is not a 1:1 mapping.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2020년 2월 11일
Input: data, an 18x1 cell array where each element is a 1xn double precision vector varying in size.
Output: a figure with x values 1:18 and y values defined by the elements of data.
% Create data that loosly match OP's description
data = arrayfun(@(i){rand(1,i)},randi(500,18,1)+27);
% Define Depths (x values_
depths = 1:numel(data);
% Create figure and plot each element of data
clf()
hold on % important
arrayfun(@(i)plot(depths(i),data{i},'o'),1:numel(depths));
% Specify the color here -----------^
200211 154948-Figure 1.png

추가 답변 (1개)

Weihao Fan
Weihao Fan 2020년 2월 12일
It works for me. Thank you.

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by