plotting figure ignore blank entries
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Emily Platt
el 19 de Mayo de 2021
Comentada: Adam Danz
el 22 de Mayo de 2021
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 comentarios
Adam Danz
el 20 de Mayo de 2021
I'm guessing your data has NaN values. You need to remove or fill in the NaN values.
Respuesta aceptada
Adam Danz
el 20 de Mayo de 2021
Editada: Adam Danz
el 20 de Mayo de 2021
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(isnan(TapsXnum)) = []
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) = []
TapsYnum(nanIdx) = []
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 comentarios
Adam Danz
el 22 de Mayo de 2021
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.
Más respuestas (1)
Mathieu NOE
el 20 de Mayo de 2021
hello
remove first the empty cells , example below (R is the cell array)
R = R(~cellfun('isempty',R));
plot(cell2mat(R))
1 comentario
Adam Danz
el 20 de Mayo de 2021
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))
cell2mat(R)
Ver también
Categorías
Más información sobre Title en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!