Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9120839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:42:57+00:00 2026-06-17T05:42:57+00:00

I have matrix A=magic(4)*10 and matrix B=[6 6 2 6; 1 1 2 1;

  • 0

I have matrix

A=magic(4)*10

and matrix

B=[6 6 2 6;  1 1 2 1; 7 7 2 1; 3 3 -1 3 ]

I want to get values of A depending on values in B. For example:

A=
160 20  30  130
50  110 100 80
90  70  60  120
40  140 150 10

B=
6   6   2   6
6   6   2   2
2   6   2   6
6   2   -1  2

I want to start at A(1,1) (value=160). Then, If the corresponding value on B, B(1,1) = 6, I want to get the element that is on the right, A(1,2), and if B(1,1) = 2, I want to get value that is below, A(2,1). Finally, if the value is -1, I do not want to proceed. In the end I want to get result like this:

result=
160
20
30
100
60

Can anyone help me please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:42:59+00:00Added an answer on June 17, 2026 at 5:42 am

    Try the following code:

    % Inizialize matices
    A=magic(4)*10;
    B=[6 6 2 6;  1 1 2 1; 7 7 2 1; 3 3 -1 3 ];
    
    % Inizialize internal variables
    contin=1;
    row=1;
    column=1;
    result=[];
    
    while contin==1
        %append value
        result=[result A(row, column)];
        if B(row, column)==6
            column=column+1; %go to the right
        elseif B(row, column)==2
            row=row+1; %go down
        elseif B(row, column)==-1
            contin=0; %break
            result(end)=[]; %delete last value 
        end
    end
    
    result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a matrix of object and I want to get an element of
Lets have matrix A say A = magic(100); . I have seen 2 ways
I have a matrix N*N, with three different values, for example 0, 0.5, 1.
I have a matrix A which I want to convert into a data.frame of
I have a matrix in MATLAB from which I want to sample every other
I have a matrix with two columns. I want to calculate running 60-day correlation
I have matrix [m x n] and vector [m], and I want to compare
I have matrix A which is a 1*11470 struct and each A, for example
I have a matrix of dimensions 20,000,000*3 stored in a file. I want to
I have a matrix of 3X3 UIbuttons, and I want to allow the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.