Concatenate string arrays of different sizes

조회 수: 12 (최근 30일)
Anna Jacobsen
Anna Jacobsen 2021년 1월 22일
댓글: Anna Jacobsen 2021년 1월 22일
Copying code from my professor for an assignment. I keep on getting the following error:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
The error makes sense to me given the context, shown below. I have never seen this sort of syntax before. Could this be a typo by my professor? Is it possible to do this?
Here is the code copied verbatim (I have excluded the plotting aspect since it involves a custom function and does not impact the string concatenation issue):
f = [0.5; 1; 1.5; 2];
Imax = 2;
% plot commands
title(['Current: [',num2str(Imax),'] nA. Frequency: [',num2str(f),'] kHz.']);

답변 (1개)

Walter Roberson
Walter Roberson 2021년 1월 22일
It is an error in the code when f is a column vector. It would work if f were a row vector. However it seems more likely that you would be looping and want to index f to get the current value for a title.
  댓글 수: 1
Anna Jacobsen
Anna Jacobsen 2021년 1월 22일
Transposing f worked, thanks so much! I think the loop approach makes more sense too–I guess we have to put all of the f values in the title since we're plotting all of their corresponding outputs at once.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by