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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:03:57+00:00 2026-05-26T00:03:57+00:00

Im v new to matlab. Have been tasked with speeding up a procedure. Im

  • 0

Im v new to matlab. Have been tasked with speeding up a procedure. Im sure there is a better way to do the following statements:

for i = 2:length(WallId)
     if WallId(i) ~= WallId(i-1)
        ReducedWallId = [ReducedWallId;WallId(i)];
        ReducedWallTime = [ReducedWallTime;WallTime(i)];
        GroupCount = [GroupCount;tempCount];
        tempCount = 1;
    else
        tempCount = tempCount +1;
    end
end

I can preallocate the various vars to ‘length(WallId)’ but what do I do with the extra after its done? Do I care?

  • 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-05-26T00:03:57+00:00Added an answer on May 26, 2026 at 12:03 am
    idx = find([true diff(WallId) ~= 0]);
    ReducedWallId = WallId(idx);
    ReducedWallTime = WallTime(idx);
    GroupCount = diff([idx numel(WallId)+1]);
    

    Assuming what you want is a summary of the unique data in WallId and WallTime, then you should
    make sure that WallId is sorted first. You can re-organise WallTime to match, as follows:

    [WallId, ind] = sort(WallId);
    WallTime = WallTime(ind);
    

    Also, you’ll only get the right answer if WallTime matches whenever WallId does.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to matlab classes and have just gone through a couple tutorials and
I am new to Matlab and have difficulty understanding global variables. For example global
I am fairly new to Matlab and have a few questions. I got two
I am new to matlab, I have a column vector with binary values I
I am very new to matlab and image processing toolbox. I have a source
I have never used Python before, most of my programming has been in MATLAB
I'm pretty new to MATLAB and I have a simple question. What if I
I am new in Matlab. I have a picture which includes a building,a person,
I am new to MATLAB. Suppose I have a vector like x = [1
I'm pretty new at Matlab so would need a baby-steps explanation. I have some

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.