Error: Inputs must be character vectors, cell arrays of character vectors, or string arrays.

Here is an example of my Variable A:
A=
"33RO30160505"
"33RO30160507"
"33RO30160508"
isstring(A) = 1.
However, I keep getting the error below:
Error using string/strcat (line 33)
Inputs must be character vectors, cell arrays of character vectors, or string arrays.
Error in initialLoading (line 196)
L2 = strcat('CODE: [', A(1), ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Does anyone know what is going on here?

 Réponse acceptée

I am not certain what result you want, however for string arrays, you can just use arithmetic operators.
Try this --
A = ["33RO30160505"
"33RO30160507"
"33RO30160508"];
L2 = "CODE: [" + A +"]"
L2 = 3×1 string array
"CODE: [33RO30160505]" "CODE: [33RO30160507]" "CODE: [33RO30160508]"
.

4 commentaires

Leon
Leon le 11 Juin 2025
Modifié(e) : Leon le 11 Juin 2025
Many thanks for the reply. I need to specify only one of the codes.
How do I do that? For example, A(1) does not work. Neither does A{1}. They trigger the error I mentioned above.
It should.
Try this --
A = ["33RO30160505"
"33RO30160507"
"33RO30160508"];
L2 = "CODE: [" + A(1) +"]"
L2 = "CODE: [33RO30160505]"
.
It turns out that the error was caused by another variable being numeric instead of a string. Sorry about that. Many thanks for your help anyway.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Produits

Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by