I am looking for a way to take the values from a matrix and sorting them into different empty arrays.

1 view (last 30 days)
Im looking for a way to take the values from matrix(given under) and sorting them into diffrent empty arrays (A and B).
A = char.empty;
B = char.empty;
vector1 = [1,0,0,0,0,1]';
vector2 = ([1,2,4,6,6,1])';
matrix = [vector2, vector1]
matrix =
1 1
2 0
4 0
6 0
6 0
1 1
My goal is to have the script recognize what values have a 1 behind it and what values have a 0 behind it so that A and B ends up looking something like this:
A = [1,1] %A being the array with values from matrix(:,1) that has a 1 in matrix(:,2)
B = [2,4,6,6] %B being the array with values from matrix(:,1) that has a 0 in matrix(:,2)
The ulttimate goal for the script segment is to have it funcion for any vector2, by manipulating vector1 from a zeroes vector using a menu system of sorts
%zero being the zeroes vector
zero = zeros(6:1)
%and want this to be manipulated using a menu or something to become a vector composed of
%ones and zeroes according to a selection in the menu
%so that it ends up looking like vector1 from the code above
Sorry if its badly formulated but my english is'nt the best in the world and my understanding of Matlab is a little subpar, so if you have questions about what im trying to achieve then feel free to ask. And thank you in advance for any help.

Accepted Answer

David Hill
David Hill on 23 Sep 2020
A=vector2(vector1==1);
B=vector2(vector1==0);
  6 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!