plotting figure ignore blank entries

조회 수: 28 (최근 30일)
Emily Platt
Emily Platt 2021년 5월 19일
댓글: Adam Danz 2021년 5월 22일
hello
i have a cell array with 5000+ rows and 1 column
i was to plot a figure but my problem is that there are many blank entries. i want the figure to consider plots from the previous entry that has a number to the next one (i.e. i will be doing a stacked time series so i dont want these empty cells to be completely ignored)
  댓글 수: 3
Adam Danz
Adam Danz 2021년 5월 20일
I'm guessing your data has NaN values. You need to remove or fill in the NaN values.
Emily Platt
Emily Platt 2021년 5월 20일
TapsX=
'321'
''
''
''
''
''
''
''
'264'
''
''
''
''
''
''
''
'301'
...
so between every value there are 7 empty cells
I want to use the plot function to make a simple one line figure

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

채택된 답변

Adam Danz
Adam Danz 2021년 5월 20일
편집: Adam Danz 2021년 5월 20일
Convert the cell array of character vectors or the string array to a numeric vector, then remove NaN values.
% Or string array: TapsX = ["123" "" "" "" "200" "" "" "321" "" ""];
TapsX = {'123' '' '' '' '200' '' '' '321' '' ''};
TapsXnum = str2double(TapsX)
TapsXnum = 1×10
123 NaN NaN NaN 200 NaN NaN 321 NaN NaN
TapsXnum(isnan(TapsXnum)) = []
TapsXnum = 1×3
123 200 321
Since you have TapsX I assume you have TapsY with the same problem. In that case you'll need to remove the elements pair-wise to maintain the paired coordinates.
TapsX = ["123" "94" "" "" "200" "" "88" "321" "" "2"];
TapsY = [ "" "94" "135" "" "200" "" "88" "" "112" "2"];
TapsXnum = str2double(TapsX);
TapsYnum = str2double(TapsY);
nanIdx = isnan(TapsXnum) | isnan(TapsYnum);
TapsXnum(nanIdx) = []
TapsXnum = 1×4
94 200 88 2
TapsYnum(nanIdx) = []
TapsYnum = 1×4
94 200 88 2
Lastly, I suspicious as to why your numeric values are represented as strings in the first place. If the are read in that way from a file, the best solution might be to read them in correctly as numeric values. Why are they strings?
  댓글 수: 2
Emily Platt
Emily Platt 2021년 5월 22일
perfect thank you. im working on exisitng data, they saved the data as strings
Adam Danz
Adam Danz 2021년 5월 22일
You shouldn't have too much trouble adapting that to your data. If you have any trouble show us what you've got and I can help straighten it out.

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

추가 답변 (1개)

Mathieu NOE
Mathieu NOE 2021년 5월 20일
hello
remove first the empty cells , example below (R is the cell array)
R = R(~cellfun('isempty',R));
plot(cell2mat(R))
  댓글 수: 1
Adam Danz
Adam Danz 2021년 5월 20일
The output is a char array. If R is a row vector, then the output is one long char vector.
R = {'123' '' '' '' '200' '' '' '321' '' ''}';
R = R(~cellfun('isempty',R))
R = 3×1 cell array
{'123'} {'200'} {'321'}
cell2mat(R)
ans = 3×3 char array
'123' '200' '321'

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

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by