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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:26:20+00:00 2026-06-04T10:26:20+00:00

I’m a newbie to Matlab and just stumped how to do a simple task

  • 0

I’m a newbie to Matlab and just stumped how to do a simple task that can be easily performed in excel. I’m simply trying to get the percent change between cells in a matrix. I would like to create a for loop for this task. The data is setup in the following format:

                DAY1 DAY2 DAY3...DAY 100

SUBJECT RESULTS

I could only perform getting the percent change between two data points. How would I conduct it if across multiple days and multiple subjects? And please provide explanation

Thanks a bunch

FOR EXAMPLE, FOR DAY 1 SUBJECT1(RESULT=1), SUBJECT2(RESULT=4), SUBJECT3(RESULT=5), DAY 2 SUBJECT1(RESULT=2), SUBJECT2(RESULT=8), SUBJECT3(RESULT=10), DAY 3 SUBJECT1(RESULT=1), SUBJECT2(RESULT=4), SUBJECT3(RESULT=5).
I WANT THE PERCENT CHANGE SO OUTPUT WILL BE DAY 2 SUBJECT1(RESULT=100%), SUBJECT2(RESULT=100%), SUBJECT3(RESULT=100%). DAY3 SUBJECT1(RESULT=50%), SUBJECT2(RESULT=50%), SUBJECT3(RESULT=50%)

updated:

Hi thanks for responding guys. sorry for the confusion. zebediah49 is pretty close to what I’m looking for. My data is for example a 10 x 10 double. I merely wanted to get the percentage change from column to column. For example, if I want the percentage change from rows 1 through 10 on all columns (from columns 2:10). I would like the code to function for any matrix dimension (e.g., 1000 x 1000 double) zebediah49 could you explain the code you posted? thanks

updated2:
zebediah49,

(data(1:end,100)- data(1:end,99))./data(1:end,99)

output=[data(:,2:end)-data(:,1:end-1)]./data(:,1:end-1)*100;

Observing the code above, How would I go about modifying it so that column 100 is used as the index against all of the other columns(1-99)? If I change the code to the following:

(data(1:end,100)- data(1:end,:))./data(1:end,:)

matlab is unable because of exceeding matrix dimensions. How would I go about implementing that?

UPDATE 3

zebediah49,

Worked perfectly!!! Originally I created a new variable for the index and repmat the index to match the matrices which was not a good idea. It took forever to replicate when dealing with large numbers.
Thanks for you contribution once again.

Thanks Chris for your contribution too!!! I was looking more on how to address and manipulate arrays within a matrix.

  • 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-04T10:26:22+00:00Added an answer on June 4, 2026 at 10:26 am

    It’s matlab; you don’t actually want a loop.

    output=input(2:end,:)./input(1:end-1,:)*100;
    

    will probably do roughly what you want. Since you didn’t give anything about your matlab structure, you may have to change index order, etc. in order to make it work.

    If it’s not obvious, that line defines output as a matrix consisting of the input matrix, divided by the input matrix shifted right by one element. The ./ operator is important, because it means that you will divide each element by its corresponding one, as opposed to doing matrix division.

    EDIT: further explanation was requested:
    I assumed you wanted % change of the form 1->1->2->3->1 to be 100%, 200%, 150%, 33%.
    The other form can be obtained by subtracting 100%.

    input(2:end,:) will grab a sub-matrix, where the first row is cut off. (I put the time along the first dimension… if you want it the other way it would be input(:,2:end).
    Matlab is 1-indexed, and lets you use the special value end to refer to the las element.
    Thus, end-1 is the second-last.
    The point here is that element (i) of this matrix is element (i+1) of the original.

    input(1:end-1,:), like the above, will also grab a sub-matrix, except that that it’s missing the last column.

    I then divide element (i) by element (i+1). Because of how I picked out the sub-matrices, they now line up.

    As a semi-graphical demonstration, using my above numbers:

    input:          [1 1 2 3 1]
    input(2,end):     [1 2 3 1]
    input(1,end-1): [1 1 2 3]
    

    When I do the division, it’s first/first, second/second, etc.

    input(2:end,:)./input(1:end-1,:):
       [1   2   3   1  ]
    ./ [1   1   2   3  ]
    ---------------------
    == [1.0 2.0 1.5 0.3]
    

    The extra index set to (:) means that it will do that procedure across all of the other dimension.

    EDIT2: Revised question: How do I exclude a row, and keep it as an index.
    You say you tried something to the effect of (data(1:end,100)- data(1:end,:))./data(1:end,:). Matlab will not like this, because the element-by-element operators need them to be the same size. If you wanted it to only work on the 100th column, setting the second index to be 100 instead of : would do that.
    I would, instead, suggest setting the first to be the index, and the rest to be data.
    Thus, the data is processed by cutting off the first:

    output=[data(2:end,2:end)-data(2:end,1:end-1)]./data(2:end,1:end-1)*100;
    

    OR, (if you neglect the start, matlab assumes 1; neglect the end and it assumes end, making (:) shorthand for (1:end).

    output=[data(2:,2:end)-data(2:,1:end-1)]./data(2:,1:end-1)*100;
    

    However, you will probably still want the indices back, in which case you will need to append that subarray back:

    output=[data(1,1:end-1) data(2:,2:end)-data(2:,1:end-1)]./data(2:,1:end-1)*100];
    

    This is probably not how you should be doing it though– keep data in one matrix, and time or whatever else in a separate array. That makes it much easier to do stuff like this to data, without having to worry about excluding time. It’s especially nice when graphing.

    Oh, and one more thing:

    (data(:,2:end)-data(:,1:end-1))./data(:,1:end-1)*100;
    

    is identically equivalent to

    data(:,2:end)./data(:,1:end-1)*100-100;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.