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 Comments

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.

Sign in to comment.

 Accepted Answer

Jan
Jan on 6 Jan 2018
Edited: Jan on 6 Jan 2018
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.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 6 Jan 2018

Edited:

Jan
on 6 Jan 2018

Community Treasure Hunt

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

Start Hunting!