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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:33:57+00:00 2026-06-05T17:33:57+00:00

Here is my MATLAB code: [numeric, pics] = xlsread(‘matrix.xls’); [r,c] = size(pics); done =

  • 0

Here is my MATLAB code:

[numeric, pics] = xlsread('matrix.xls');
[r,c] = size(pics);
done = r*c;

randvecall = randsample(done, done, true);
randvec = randvecall([1,diff(randvecall)]~=0);
currk = randvec(k);

Essentially what this does is it builds an array of values from a Microsoft Excel spreadsheet. I want to have duplicates in the array, but not consecutive duplicates, so I added a line of code that removes them. When I manually enter values into randvecall and run the above code, it works perfectly. However, when I run the code as seen above, I get the following error:

??? Error using ==> horzcat
CAT arguments dimensions are not consistent.

Error in ==> testAS_randsample at 76
randvec = randvecall([1,diff(randvecall)]~=0);

Why is this happening? For example, this works:

randvecall=[1 2 3 4 5 5 5 5 8 7 8 8];
randvec = randvecall([1,diff(randvecall)]~=0);
disp(randvec)

randvec = [1 2 3 4 5 8 7 8]

That is exactly what I want my code to do. But why does my actual code give me the horzcat error message? Can anybody help me with this? It must have something to do with the way randsample is building the randvecall array, but I can’t figure out why this would give me that error message?

  • 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-05T17:33:59+00:00Added an answer on June 5, 2026 at 5:33 pm

    That seems to be a problem with how randsample(n,k,true) works: it returns a 1xk vector, while you need a kx1 vector. Transposing randvecall should do the trick.

    EDIT:

    Let me rephrase it in code for the general reader:

    randvec = randvecall([1,diff(randvecall')]~=0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just wonder how to add annotation in matlab plot? Here is my code:
Here is the MATLAB / FreeMat code I got to solve an ODE numerically
Here's the code used in my .bat file phreeqc first_trial_um_b.pqi matlab -sd C:\trialbatch -r
Ok, here's some code in MATLAB: data = [1 1.5 2 3 4 4.5
I'm trying to perform a really simple summation in MATLAB. Here is my code:
I'm using k-means with matlab on a big and sparse matrix ~(1000000x1000). Now here
Here is the matlab code: javaclasspath(pwd); % set java path to current working directory
Here is piece of Matlab code. It works very slow. Is there any way
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here's the code in AlertTableView: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSInteger index = 12345; NSLog(@AlertTableView:

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.