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 8601485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:51:20+00:00 2026-06-12T01:51:20+00:00

I am looking to apply an IF statement to a matrix like the following:

  • 0

I am looking to apply an IF statement to a matrix like the following:

A =

 2     5     2     4     8
 2     5     0     0     0
 2     4     0     0     0
 6     8     0     0     0
 9     5     0     0     0
 4     7     0     0     0
 8     1     0     0     0

What I have so far is this:

if A(1,2)>A(1,4),
A(2,3)=A(1,4);
A(2,4)=(A(1,5))+1;
end


if A(1,2)<A(1,4),
A(2,4)=(A(1,4))-1;
A(2,4)=(A(1,4))-(A(2,3));
end

In the aforementioned code I am only comparing the 2nd and 4th column of the first row.
Then the first row constructs the second row.

I am looking to then compare the second row and use that to construct the third row … and so on … throughout all 7 rows.

Could I add a 1:n to modify this?

Any suggestions?

  • 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-12T01:51:21+00:00Added an answer on June 12, 2026 at 1:51 am

    You can write the following loop

    for i=1:size(A, 1)-1
        if A(i,2)>A(i,4),
            A(i+1,3)=A(i,4);
            A(i+1,4)=A(i,5)+1;
        end 
        if A(i,2)<A(i,4),
            A(i+1,4)=A(i,4)-1;
            % wrong index here? You assign twice to the same A entry.
            % the above line has no effect...
            A(i+1,4)=A(i,4)-A(i+1,3);
        end 
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking for best advice on how to do this: I have an insert like
I'm looking for something similar to this: Active navigation with jQuery - can't apply
Looking at some assembly code for x86_64 on my Mac, I see the following
Looking to do a bit of refactoring... Using NHibernate I have this query currently
First I would like to say that I have only worked with java for
I am looking for a built-in extension method like Apply: collection.Apply (predicate) which will
looking in internet how put a shadows to my containers i found this code
I'm looking for a concise and functional style way to apply a function to
Looking at the Ehcahce implementation of net.sf.cache.JS107, I am trying to achieve the following
I'm looking back at the Backbone todo list and have a question about the

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.