Adding String variables to an Array of differing size
Afficher commentaires plus anciens
I'm coding for a personal project and I've ran into a roadblock for me. I want to add string values to an array that changes size depending on how many values there are. Here's an example:
str_val_init = ["Hello","World","How","Are","You"];
str_val_need = zeros([1 x])
x = 0;
num = [2,3,3] %the real num array is random
for idx = 1:numel(num)
ind = num(idx)
if ind == 2
x = x + 1
str_val_need = str_val_init(1,1);
elseif ind == 3
x = x + 1
str_val_need = str_val_init(1,2)
else
end
end
I keep getting the error "Unable to perform assignment because value of type 'string' is not convertible to 'function_handle'." Really I just want to know how to continue adding string values to an array that changes size.
1 commentaire
Steven Lord
le 21 Août 2021
This seems quite similar to this other Answers post in which Cris LaPierre and I have posted answers. Perhaps you can use what you learned in that discussion here?
Réponses (0)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!