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 次查看(过去 30 天)
显示 更早的评论
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 个评论
Rohit Deshmukh
2020-2-28
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.
采纳的回答
Image Analyst
2013-10-4
编辑:Image Analyst
2013-10-4
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 个评论
Steven Lord
2022-7-14
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')
更多回答(3 个)
Vidhya Dharshini
2013-10-4
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 个评论
Image Analyst
2013-10-4
But you're overwriting T every time, plus sometimes it's a double and other times it's a character string.
Ruben
2022-7-14
编辑:Ruben
2022-7-14
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 个评论
Image Analyst
2022-7-14
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!