I want to transfer strings in an array to another array

I am trying to transfer strings of words in an array to another array if I define that word as 1. Here is my code atm. prompt = 'Define'; AB1=0; for aa = 1:BoxA wordsA(aa) AA(aa)=input(prompt) %state 1/0 depending if AA(aa) == 1 %if statement if 1 so it goes to another array AB1+1; wordsAB(AB1)=wordsA(aa) end end I get an error saying "Subscript indices must either be real positive integers or logicals." I can't find a tag or solution relating to this.

2 个评论

What is a "string of words"? What does "transfer" mean? Please read Format code to make your code readable. Please post the complete error message, such that the readers do not have to guess in which lines the problem occurs.

请先登录,再进行评论。

 采纳的回答

AB1=0;
for aa = 1:BoxA
...
AB1+1; % This statement does nothing! AB1 remains 0
wordsAB(AB1)=wordsA(aa)
end
"AB1+1" calculates AB1+1, but it does not assign the result to a variable. Most likely you want:
AB1 = AB1+1;
Do you know the debugger already? See https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html . You can set a breakpoint into the first line and step through your code line by line. Inspect the values of the variables e.g. in the WorkSpace browser. Then you will find this problem by your own easily.

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by