Error using + Matrix dimensions must agree.

7 Ansichten (letzte 30 Tage)
Gonçalo Cordeiro
Gonçalo Cordeiro am 4 Jun. 2018
Beantwortet: Walter Roberson am 4 Jun. 2018
this is my code:
results = '';
for i = 1 : 1 : length(BBArray)
results = results + sprintf('%.0f\t' , BBArray(i, :))+'\n';
results + sprintf('%.0f\t' , BBArray(i, :))+'\n';
end
results;
how can i improve?
  2 Kommentare
Shrestha Kumar
Shrestha Kumar am 4 Jun. 2018
What do you want to do with this code? You want to concatenate each row of the matrix to results??
Gonçalo Cordeiro
Gonçalo Cordeiro am 4 Jun. 2018
yes i want this

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 4 Jun. 2018
You cannot use + to concatenate character vectors.
If you are using R2017a or later, you could change the initial
results = '';
to
results = "";
and that would have you working with string objects instead of character vectors, which would support using + for concatenation.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by