help on graph (w/o common matrix plotting built-in functions)

1 回表示 (過去 30 日間)
Patrick Laux
Patrick Laux 2022 年 5 月 20 日
編集済み: Voss 2022 年 5 月 21 日
Dear all,
based on a matrix of zeros and ones, let's say 10 x 365 (10 years a 365 days), I would like to plot a '-' for a one and leave the position blank ' ' for a zero.
Thus, the graph should e.g. look like:
....
------ --- --- ---- ---- ------ ----- --
-------- ------ --------------- -----------
------ -- ---------- --------- ---------
----- --------------- ------ ---------- -
.....
Any hint appreciated.

採用された回答

Les Beckham
Les Beckham 2022 年 5 月 20 日
In that case, maybe something like this will get you close.
A = randi(2,10,365)-1;
x = 1:size(A,2);
y = size(A,1):-1:1;
for i = 1:size(A,1)
A(i,:) = A(i,:)*y(i);
end
A(A==0) = NaN;
for i = 1:size(A,1)
line(x, A(i,:), 'Marker', '_', 'linestyle', 'none', 'MarkerSize', 0.1)
end

その他の回答 (5 件)

Les Beckham
Les Beckham 2022 年 5 月 20 日
A = randi(2,10,365)-1
A = 10×365
1 1 1 1 1 1 1 1 0 1 0 1 1 0 1 1 0 0 0 0 0 0 1 1 0 1 1 0 1 0 1 0 0 1 0 1 1 0 0 0 1 0 0 1 0 0 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 1 1 0 1 0 1 1 1 1 0 1 1 0 0 0 0 1 1 0 0 0 1 1 1 1 0 0 0 1 0 0 1 0 1 1 1 1 0 1 1 0 0 0 0 1 0 0 0 1 1 1 1 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 1 1 0 1 1 0 0 0 0 1 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 0 1 1 0 0 1 1 0 0 1 1 1 0 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 0 1 1 0 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 1 0 0 0 0 0 1 0 0 1 0 0 1 1 1 0 1 1 1 0 0 1 0 1 0 1 0 0 1 0 0 0 1 1 1 0 1 0 0 1
str = repmat(' ', size(A));
str(A==1) = '-';
disp(str)
-------- - -- -- -- -- - - ------ - --- --- -- - - - - - -- --- - --- - -- - -- -- -- --- ---- -- --- ---- - - - - -- - ------- - - - - - ---- --- - -- --- - -- - --- - -- - - - ----- --- ---- ------- - - - - --- - ------- ---- -- -- - - - -- - -- - - - - -- - ---- -- -- - -- --- - - - -- - - -- ----- - - ---- ---- -- - -- ------- --- - - - - --- ---- - - - - - -- - - ---- - - - ------ ------ - --- --- -- -- - - - -- - - -- --- -- - ----- -- - - -- ---- ---- - -- - - - --- - - -- - - -- - -- - - - - - -- -- - --- -- --- - -- - - - --- - -- -- - ---- -- - ---- -- -- --- --- -- -- - - - ----- ---- - - ---- - - ---- - --- - -- --- -- - --- --- ----- -- -- --- - -- - --- - --- - --- --- ------ -- - -- - - ----- - --- ----- -- - - - ------ ---- - - -- --- ----- - - --- -- -- - - ----- - - - - ----- - - - ----- -- - - - - - ---- -- - ---- --- - ------ - - -- - -- ---- - - ---- --- ---- --- - --- - - - - - -- ------ ---- --- - --- - -- ------ --- -- -- - -- -- - ----- --- - - - --------- - - ---- - --- - - -- ----- --- --- - -------- ---- - - ------- -- - - ---- - - -- - - ---- --- - - - - - - -- - -- -- --- --- - -- - -- ---- - - -- - --- -- - - --- --- - - - - - ----- ----- -- - -- -- --- - -- -- - - - ---- - -- --- - -- - -- -- ----- ---------- - ---- -- -- - -- - - - ---- ----- - --- - -- - ------ - ---- -- - - - - - - -- - --- --- -- ---- - - - - - - - - - - - -- -- --- -- - ---- - --- - ---- - - - -- ---- - --- - - - --- - ----- -- ---- ---- - - ----- -- - - - -- - - --- - -- -- - - - --- -- - - -- - -- - - - -- -- - - -- --- - - - - - - - - ---- - -- - ----- - --- - - - - - -- - -- - --- -- - - - - -- --- --- - -- --- -- -- ---- --- - - - - - - -- - - -- - ----------- - - - ------ - - - --- -- - - - --- -- -- - - --- - - -- -- ---- - ---- - -- - ------- - - - - ---- ----- -- ---- - ---- ---- - -- - - - -- - - - - - - --- -- - --- ---- -- ------- -- -- - - - - - - - --- - -- --- --- - - - ----- - -- - -- - - --- ------- - -- -- - -- --- - - -- --- --- -- --- -- ------ -- - --- --- -- - ---- - - -- ---- -- - --- - -- - - - --- -- --------- -- - --- - - - --- - ---- -- - - --- - - -- ----- - - -- - --- --- - - - - - --- - -- ---- -- --- - -- -- - --- ------- - -- --- -- - ------- - - - - - - - -- ----- - - - - - -- - - - -- - - -- -- ---- -- -- -- -- - --- -- - -- - --- - ------ - - ---- -- -- - ----- - - - -- -- - -- - - ----- - -- - --- - --- - - - - -- -- --- - - - -- - --- --- --- - ---- - - - ---- - ---- -- - - -- - -- -- - -- ---- - - - - - - --- --- - - - - --- - -- -- - --- - --- -- - ---- ------- -- --- --- - - -- - - - - - -- - - ---- -- -- --- -- --- - - - --- - -- - -- --- - --- -- - - ---- - - - --- - - -- ---- --- - -- -- -- -- -- --- --- - - -- -- --- --- ---- -- -- ----- - -- - - -- ----- - -----
  3 件のコメント
Les Beckham
Les Beckham 2022 年 5 月 20 日
How clever! I'm suprised that that works. I would have never thought to index into a 1x2 array with a larger index array.
Steven Lord
Steven Lord 2022 年 5 月 21 日
The size of the index array doesn't matter for linear indexing. What matters are the values in that array.

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


Patrick Laux
Patrick Laux 2022 年 5 月 20 日
excellent already, but actually I thought about having a real figure with xaxis and yaxis. Sorry that I was not very clear here.
  1 件のコメント
Steven Lord
Steven Lord 2022 年 5 月 21 日
A = randi([0 1], 5, 5)
A = 5×5
1 0 0 1 1 1 1 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 0 1 1
spy(A)
If you really want dashes:
figure
spy(A, '_')

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


DGM
DGM 2022 年 5 月 20 日
編集済み: DGM 2022 年 5 月 20 日
In the spirit of ridiculousness, here is my attempt:
% random binary data
data = randi([0 1],10,10)
data =
1 1 0 0 1 1 1 1 0 0
0 0 0 1 0 1 1 1 1 1
0 0 0 1 1 0 0 0 1 0
1 1 1 1 0 1 0 0 1 0
0 1 0 1 0 1 1 0 1 1
0 1 0 1 0 0 1 1 1 0
0 0 1 0 1 0 1 0 0 0
0 0 0 0 0 1 1 0 0 1
1 0 0 0 1 1 0 1 0 1
0 1 1 0 0 1 0 1 0 1
% convert to char data (space and full-width crossbar)
charmap = char([32 196]);
chardata = charmap(data+1)
chardata =
10×10 char array
'ÄÄ ÄÄÄÄ '
' Ä ÄÄÄÄÄ'
' ÄÄ Ä '
'ÄÄÄÄ Ä Ä '
' Ä Ä ÄÄ ÄÄ'
' Ä Ä ÄÄÄ '
' Ä Ä Ä '
' ÄÄ Ä'
'Ä ÄÄ Ä Ä'
' ÄÄ Ä Ä Ä'
% construct an image by flowing char glyphs into a rectangular box
charsize = [8 8]; % depends on the selected font
datasize = size(chardata);
tsize = [NaN datasize(2)*charsize(2)+charsize(2)/2];
outpict = textblock(chardata(:)',tsize,'font','compaq-8x8','tightwidth',true,'hardbreak',true);
% display the image with character-centered tickmarks
xrange = 0.5:datasize(1)+0.5;
yrange = 0.5:datasize(2)+0.5;
imagesc(xrange,yrange,1-outpict)
colormap(gray)
Alternatively, instead of using a full crossbar, you can just use
charmap = ' -';
and get
Bear in mind those are different random data. The point is that the bars don't touch.
This uses a few tools from MIMT, namely textblock() and imstacker().

Patrick Laux
Patrick Laux 2022 年 5 月 21 日
great answers! Thank you very much, very helpful

Voss
Voss 2022 年 5 月 21 日
編集済み: Voss 2022 年 5 月 21 日
data = randi([0 1],10,30)
data = 10×30
0 0 1 1 0 1 1 1 1 0 1 0 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 0 1 1 0 1 0 1 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 1 0 1 0 0 0 1 0 1 1 1 1 0 1 1 0 0 0 0 0 1 1 0 1 1 0 0 1 0 1 0 0 1 0 0 1 1 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 0 1 0 1 0 0 0 1 1 1 1 1 1 0 0 1 0 1 0 1 0 1 0 1 0 1 1 0 0 1 1 1 0 1 1 1 1 0 0 1 0 1 0 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 0 1 1 0 0 1 0 1 1 1 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 0 1 0 0 0 1 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 1 1 0 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 0 0 1 0 1 1 0 1 1 0 0 1 1 1 0 0 0 0 1 0 1 0 0 1 1 0 1
imshow(1-data)

カテゴリ

Help Center および File ExchangeDiscrete Data Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by