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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:18:36+00:00 2026-05-26T05:18:36+00:00

I am using Matlab, and I have a 1×200 vector of numbers. I need

  • 0

I am using Matlab, and I have a 1×200 vector of numbers.

I need to assign a “score” to the set of numbers by following these rules:

  1. If there are 2 or 3 or 4 consecutive positive numbers, then 0.5 points
  2. If there are five or more consecutive positive numbers, then 1.0 points
  3. If there isn’t any consecutive positive number, for example: 0 0 0 6 0 0, then 0.0 point. (ignore it, consider that positive number as zero)
  4. If there is only one zero in the middle of a run of positive integers, then ignore that zero (consider it as a positive integer)
  5. If there are two or more consecutive zeroes, that breaks the run of consecutive positive numbers.

Example: 30 43 54 0 0 0 41 54 14 10 1 0 0 0 0 32 41 98 12 0 0 0 (2.0 points total)

At the end, there should be a tally of the points.

Are there any useful functions for this type of problem?

  • 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-26T05:18:37+00:00Added an answer on May 26, 2026 at 5:18 am

    This is based on my understanding of the question, as noted in my question above. I’ve “unsuppressed” all output, so you can see what’s going on.

    %Rules:
    %1. If there are 2 or 3 or 4 consecutive positive numbers, then 0.5 point
    %2. If there are five or more consecutive positive numbers, then 1.0 point
    %3.  And if there isn't any consecutive positive number, for example: 
    %   0 0 0 6 0 0, then 0.0 point. (ignore it, consider that positive 
    %   number as zero)
    %4. if there is only one zero in the middle of positive integers = ignore 
    %   that zero (consider it as a positive integer)
    %5. If there are two or more consecutive 0, THEN no point.
    
    %testData = [0 30 43 54 0 0 0 41 54 14 10 1 0 0 0 0 32 41 98 12 0 0 0 1 2 0 1 2 0 ];
    testData = [30 43 54 0 0 0 41 54 14 10 1 0 0 0 0 32 41 98 12 0 0 0 ];
    posa = testData>0;
    %add 0s at each end so that the diffs at the ends work.
    diffa = diff([0 posa 0])
    starts = find(diffa ==1)
    ends = find(diffa==-1)
    
    % Rule 4 if any end (-1) is immediately followed by a start, that means that there 
    %   is a 0 in the middle of a run.  substitute a 1 in the position and recalc.
    midZeroLengths = starts(2:end) - ends(1:(end-1));
    %pad to account for the fact that we only compared part.
    midZeroLengths = [midZeroLengths 0];
    if any(midZeroLengths == 1);
        testData(ends(midZeroLengths==1)) = 1;
        posa = testData>0;
        %add 0s at each end so that the diffs at the ends work.
        diffa = diff([0 posa 0])
        starts = find(diffa ==1)
        ends = find(diffa==-1)  
    end
    
    runs = ends-starts
    halfs = (runs > 1) & (runs < 5)
    wholes = (runs > 4)
    final = sum(halfs)*0.5 + sum(wholes)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some differential equations that I need to solve using MATLAB's ODE solvers.
Using MATLAB, you have to start with a uniform distribution between (0,1). You need
I'm using MATLAB. I have a matrix with N elements filled with numbers [1;
How can I generate a set of image projections using MATLAB ? I have
I often have to run calculation intensive simulations using Matlab. These simulations often take
Using MATLAB, I have this code: value = input('>> Enter a value: '); and
I have been using Matlab 2011b and contourf/contourfm to plot 2D data on a
I have an assignment to create a GUI using MATLAB GUIDE and am having
I have been given some matlab code compiled using the .net compiler. I can
I have some data generated in MATLAB that I want to process using Perl.

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.