Adding String variables to an Array of differing size

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

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?

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2021a

태그

질문:

2021년 8월 21일

댓글:

2021년 8월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by