フィルターのクリア

How to write the matrix with blank element?

39 ビュー (過去 30 日間)
suvadip paul
suvadip paul 2013 年 10 月 4 日
コメント済み: Ruben 2022 年 7 月 18 日
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 件のコメント
suvadip paul
suvadip paul 2013 年 10 月 4 日
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
Rohit Deshmukh
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
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
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')
Ruben
Ruben 2022 年 7 月 18 日
Thank you @Steven Lord, that solved my issue!

サインインしてコメントする。

その他の回答 (3 件)

Vidhya Dharshini
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
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
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([],[],[]))]

Image Analyst
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 件のコメント
Ruben
Ruben 2022 年 7 月 18 日
Oh I understand now. Thanks for explaining that to me and sending me the tutorial.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by