Converting a matrix to string

9 ビュー (過去 30 日間)
Irene Nadal Arizo
Irene Nadal Arizo 2021 年 10 月 11 日
回答済み: David Hill 2021 年 10 月 11 日
Hello community,
This question is probably really simple, but i cant find a way to solve this error
I have three matrices of numbers: X (MxN), Y(MxN) and Z (MxN). In my specific case, X is a matrix of longitudes, Y is a matrix of latitudes and Z is a matrix of depths. I want to display Z values in the X and Y positions dynamically using "text" function, so first, I have to convert Z numbers to strings. Well, when I use numstr(Z), I want to obtain a matrix with MxN vectors of strings, but conversely, I obtain an unique char so I can't use Z for text.
Example:
X = rand(3,3); Y = rand(3,3); Z = rand(3,3);
z = num2str(Z);
%% whos z
%%Name Size Bytes Class Attributes
%% z 3x31 186 char
%% I OBTAIN z(3x31) INSTEAD OF z(3x3)
figure
plot(X,Y,'.')
text(X,Y,z)

採用された回答

KSSV
KSSV 2021 年 10 月 11 日
編集済み: KSSV 2021 年 10 月 11 日
X = rand(3,3); Y = rand(3,3); Z = rand(3,3);
figure
plot(X,Y,'.')
text(X(:),Y(:),num2str(Z(:)))

その他の回答 (1 件)

David Hill
David Hill 2021 年 10 月 11 日

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by