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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:31:15+00:00 2026-05-19T14:31:15+00:00

new_img is ==> new_img = zeros(height, width, 3); curMean is like this: [double, double,

  • 0

new_img is ==>

new_img = zeros(height, width, 3); 

curMean is like this: [double, double, double]

new_img(rows,cols,:) = curMean;

so what is wrong here?

  • 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-19T14:31:16+00:00Added an answer on May 19, 2026 at 2:31 pm

    The line:

    new_img(rows,cols,:) = curMean;
    

    will only work if rows and cols are scalar values. If they are vectors, there are a few options you have to perform the assignment correctly depending on exactly what sort of assignment you are doing. As Jonas mentions in his answer, you can either assign values for every pairwise combination of indices in rows and cols, or you can assign values for each pair [rows(i),cols(i)]. For the case where you are assigning values for every pairwise combination, here are a couple of the ways you can do it:

    • Break up the assignment into 3 steps, one for each plane in the third dimension:

      new_img(rows,cols,1) = curMean(1);  %# Assignment for the first plane
      new_img(rows,cols,2) = curMean(2);  %# Assignment for the second plane
      new_img(rows,cols,3) = curMean(3);  %# Assignment for the third plane
      

      You could also do this in a for loop as Jonas suggested, but for such a small number of iterations I kinda like to use an “unrolled” version like above.

    • Use the functions RESHAPE and REPMAT on curMean to reshape and replicate the vector so that it matches the dimensions of the sub-indexed section of new_img:

      nRows = numel(rows);  %# The number of indices in rows
      nCols = numel(cols);  %# The number of indices in cols
      new_img(rows,cols,:) = repmat(reshape(curMean,[1 1 3]),[nRows nCols]);
      

    For an example of how the above works, let’s say I have the following:

    new_img = zeros(3,3,3);
    rows = [1 2];
    cols = [1 2];
    curMean = [1 2 3];
    

    Either of the above solutions will give you this result:

    >> new_img
    
    new_img(:,:,1) =
    
         1     1     0
         1     1     0
         0     0     0
    
    new_img(:,:,2) =
    
         2     2     0
         2     2     0
         0     0     0
    
    new_img(:,:,3) =
    
         3     3     0
         3     3     0
         0     0     0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I write something like this: var img = $(new Image()).attr('src', image.src); How can
I have a Div layer like this ... <style type=text/css> <!-- #newImg { position:absolute;
I'd like to modify this PictureBox Array Project. i want to put a reset
I've been working through the Oracle tutorial for images this one here: import java.awt.*;
If you do this in MVC: var jsonData = new { myimage = <img
New to javascript/jquery and having a hard time with using this or $(this) to
New to silverlight. Traditionally if I were to design a wizard-like process where a
I have this function to store the bmp image in a desired location as
Hey all, i've been working on this small project in XNA the goal is
new_img = convert(img, text); (img, text) = convert_back(new_img); Can someone illustrate with a built-in

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.