if T(6) cannot left blank, then I want to display T(6)= ND (Not defined) so that T= 2 4 6 8 10 ND 14 16 18 20
How to write the matrix with blank element?
53 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
suvadip paul
el 4 de Oct. de 2013
Comentada: Ruben
el 18 de Jul. de 2022
for i=1:10
if i~=6 T(i)=2*i
else T(i)= %(i want to leave it blank) end end
T
Is this possible in Matlab? If yes, How to do this?
2 comentarios
Rohit Deshmukh
el 28 de Feb. de 2020
is there any possibility of keeping the element blank?
I do not want nan or ND nor do i want to delete the element from matrix.
Respuesta aceptada
Image Analyst
el 4 de Oct. de 2013
Editada: Image Analyst
el 4 de Oct. de 2013
Just set those elements to nan:
T(i) = nan;
otherwise you'd be looking at a cell array and that's a lot more complicated to use and you probably don't want the hassles of dealing with those. Nan means "Not a number" and is basically the concept of "not defined' that you're trying to achieve. They just call it nan instead of ND.
8 comentarios
Steven Lord
el 14 de Jul. de 2022
It is not possible to have an array in MATLAB (except for a Java array) that has "holes" in it.
For the question about tick labels on an axes where you've plotted a datetime array, that's not too difficult. Here's one with tick labels every day.
v = 0:10;
x = datetime('today') + days(v);
y = v.^2;
plot(x, y)
xticks(x)
title('Labels each day')
Here's one with a tick every day and a tick label every other day.
figure
plot(x, y)
xticks(x)
% Customize how the label strings are formatted
x.Format = 'MMM dd';
s = string(x);
s(2:2:end) = "";
xticklabels(s)
title('Labels every other day')
Más respuestas (3)
Vidhya Dharshini
el 4 de Oct. de 2013
Hi... try this
for i=1:10
if(i~=6)
T=2*i
else
T='ND'
end;
T
end
just give T='ND' and it will display.
1 comentario
Image Analyst
el 4 de Oct. de 2013
But you're overwriting T every time, plus sometimes it's a double and other times it's a character string.
Ruben
el 14 de Jul. de 2022
Editada: Ruben
el 14 de Jul. de 2022
Thanks for getting back to me!
Like @Rohit Deshmukh, I would like to have blank elements in my vector (or maybe it's a "datetime array"?)
I'm plotting millions of lines of data in monthly chunks. For my plots I want xticks for every day but xtick labels only every other (second) day. In other words I want minor tickmarks every day, and major tickmarks every other day (I know there is the XMinorTick 'on' option, but I haven't figured that out yet so I'm also trying this strategy).
Below, I'm trying to include these blanks in my array, but instead of reading datetime([],[],[]) as a physical blank space, it just skips over it, leaving me with only the major tickmarks.
% data is collected every minute
timestartm = datetime(2022,02,01);
timeendm = datetime(2022,02,28);
xlimit = [timestartm timeendm];
xtki = 2; % xtick interval is 2
xtkl = [(timestartm) (datetime([],[],[])) (timestartm + xtki) (datetime([],[],[])) (timestartm + 2*xtki)...
(datetime([],[],[])) (timestartm + 3*xtki) (datetime([],[],[])) (timestartm + 4*xtki) (datetime([],[],[]))...
(timestartm + 5*xtki) (datetime([],[],[])) (timestartm + 6*xtki) (datetime([],[],[]))...
(timestartm + 7*xtki) (datetime([],[],[])) (timestartm + 8*xtki) (datetime([],[],[]))...
(timestartm + 9*xtki) (datetime([],[],[])) (timestartm + 10*xtki) (datetime([],[],[]))...
(timestartm + 11*xtki) (datetime([],[],[])) (timestartm + 12*xtki) (datetime([],[],[]))...
(timestartm + 13*xtki) (datetime([],[],[])) (timestartm + 14*xtki) (datetime([],[],[]))]
0 comentarios
Image Analyst
el 14 de Jul. de 2022
You're posting this as an "Answer" to a question that people can see (by the green box) that has already been successfully answered. So many people will not open this and look at your question. Again it's best if you start a new question - not anywhere here in this discussion thread, but a brand new question all your own. More people will see it and answer it then.
If you can mock up some desired output, whether it's some numbers or a picture of something you drew in Photoshop, such as a plot or whatever. But people need to see what you'd like to achieve as a solution.
1 comentario
Ruben
el 18 de Jul. de 2022
Oh I understand now. Thanks for explaining that to me and sending me the tutorial.
Ver también
Categorías
Más información sobre NaNs 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!