vertical concatenate strings in msgbox

4 ビュー (過去 30 日間)
Jason
Jason 2023 年 1 月 28 日
編集済み: Jason 2023 年 1 月 28 日
Hello,I cant understand why this vertical concatenation of strings isn't working.
v = VideoReader(filename); % Create Videoreader object
%Get info from video
D=['Duration(s): ',num2str(v.Duration,'%.2f')]
B=['BitsperPixel: ',num2str(v.BitsPerPixel)]
F=['FrameRate: ',num2str(v.FrameRate)]
N=['Num Frames: ',num2str(v.NumFrames)]
mstr=([D;F;B;N])
f = msgbox(mstr,'icon','help');
waitforbuttonpress; %Block matlab until msgbox button is pressed
Gives an error: Dimensions of arrays being concatenated are not consistent

採用された回答

cdawg
cdawg 2023 年 1 月 28 日
編集済み: cdawg 2023 年 1 月 28 日
Each one of those isn't a string. If you look at D, F, B, and N in your workspace they are character vectors. For example, if I choose a value for duration:
D = ['Duraction(s): ', num2str(100)];
ischar(D)
ans = logical
1
length(D)
ans = 17
D is as long as however may characters it has. That would mean that each of the vectors your concatenating would need to have the same number of characters.
But if I use "string" instead of 'character'
D=["Duration(s): ",num2str(100)];
isstring(D)
ans = logical
1
length(D)
ans = 2
Each vector will have a length of 2. If you want Duration and num2str to be together in one cell, try using strcat()
D=strcat("Duration(s): ",num2str(100));
B=strcat("BitsperPixel: ",num2str(1000));
F=strcat("FrameRate: ",num2str(10000));
N=strcat("Num Frames: ",num2str(1000));
mstr=([D;F;B;N])
mstr = 4×1 string array
"Duration(s): 100" "FrameRate: 10000" "BitsperPixel: 1000" "Num Frames: 1000"
  3 件のコメント
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 1 月 28 日
編集済み: Sulaymon Eshkabilov 2023 年 1 月 28 日
Here strcat is not necessary. The straight and complete answer is the use of {} instead of [ ] to have the messaeg in the msgbox.
% v = VideoReader(filename); % Create Videoreader object
%Get info from video
v.Duration=4.70;
v.BitsPerPixel = 24;
v.FrameRate=30;
v.NumFrames=141;
D=['Duration(s): ',num2str(v.Duration,'%.2f')]
D = 'Duration(s): 4.70'
B=['BitsperPixel: ',num2str(v.BitsPerPixel)]
B = 'BitsperPixel: 24'
F=['FrameRate: ',num2str(v.FrameRate)]
F = 'FrameRate: 30'
N=['Num Frames: ',num2str(v.NumFrames)]
N = 'Num Frames: 141'
mstr=({D;F;B;N}) % Use braces
mstr = 4×1 cell array
{'Duration(s): 4.70'} {'FrameRate: 30' } {'BitsperPixel: 24' } {'Num Frames: 141' }
f = msgbox(mstr,'icon','help');
Jason
Jason 2023 年 1 月 28 日
編集済み: Jason 2023 年 1 月 28 日
Oh i see, thankyou. Sorry i didnt accept your answer

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

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 1 月 28 日
Here is the corrected code:
v = VideoReader(filename); % Create Videoreader object
%Get info from video
D=['Duration(s): ',num2str(v.Duration,'%.2f')]
B=['BitsperPixel: ',num2str(v.BitsPerPixel)]
F=['FrameRate: ',num2str(v.FrameRate)]
N=['Num Frames: ',num2str(v.NumFrames)]
mstr=({D;F;B;N}) % Use braces
f = msgbox(mstr,'icon','help');
waitforbuttonpress; %Block matlab until msgbox button is pressed

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by