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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:36:01+00:00 2026-05-25T16:36:01+00:00

I Have my function below, the idea being that X is a 3×3 extract

  • 0

I Have my function below, the idea being that X is a 3×3 extract from T to be used in the loop, it correctly extracts the 3 rows but for some reason produces far too many columns, see example below.

function T = tempsim(rows, cols, topNsideTemp, bottomTemp, tol)
    T = zeros(rows,cols);
    T(1,:) = topNsideTemp;
    T(:,1) = topNsideTemp;
    T(:,rows) = topNsideTemp;
    T(rows,:) = bottomTemp;
    S = [0 1 0; 1 1 1; 0 1 0]; 
    X = zeros(3,3);
    A = zeros(3,3);
    for ii = 2:(cols-1);
        jj = 2:(rows-1);
        X = T([(ii-1) ii (ii+1)], [(jj-1) jj (jj+1)])
        A = X.*S;
        T = (sum(sum(A)))/5 
    end

test sample

EDU>> T = tempsim(5,4,100,50,0)

X =

   100   100   100   100   100   100   100   100   100
   100     0     0     0     0     0     0     0   100
   100     0     0     0     0     0     0     0   100


ans =

   100   100   100   100   100   100   100   100   100
   100     0     0     0     0     0     0     0   100
   100     0     0     0     0     0     0     0   100

??? Error using ==> times
Matrix dimensions must agree.

Error in ==> tempsim at 14
    A = X.*S;

any thoughts on how to fix this?

  • 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-25T16:36:02+00:00Added an answer on May 25, 2026 at 4:36 pm

    There’s no need to preallocate X and A if you do a complete assignment anyway. Then, you replace T with a scalar inside the loop, which makes you run into problems in the next iteration. What I’m guessing you want could look something like this:

    function T = tempsim(rows, cols, topNsideTemp, bottomTemp, tol)
      T = zeros(rows,cols);
      T(1,:) = topNsideTemp;
      T(:,1) = topNsideTemp;
      T(:,rows) = topNsideTemp;
      T(rows,:) = bottomTemp;
      S = [0 1 0; 1 1 1; 0 1 0]; 
      for ii = 1:(cols-2);
        for jj = 1:(rows-2);
          X = T(ii:ii+2, jj:jj+2);
          A = X.*S;
          T(ii,jj) = (sum(sum(A)))/5;
        end
      end
    

    Although I’m not sure if you really mean to do that – you’re working on T while modifying it. As a wild guess, I suspect you might be looking for something like

    conv2(T, S/5, 'same')
    

    instead, perhaps after making your fixed-temp borders twice as thick and re-setting them after the call (since conv2 does zero-padding at the outer borders).

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

Sidebar

Related Questions

I have an example function below that reads in a date as a string
I have a function that resembles the one below. I'm not sure how to
HI, I have a generic function as shown below. It can be used to
I have a function that need to sum up from each input but at
let say i have function like below function doSomethingNow(){ callSomethingInFutureNotExistNow(); } at the moment
I have written a function below: void trans(double x,double y,double theta,double m,double n) {
I have the following function below: public function setupHead($title){ $displayHead .='<!DOCTYPE html PUBLIC -//W3C//DTD
I have template function compare defined as below. #include<iostream> using namespace std; template<typename T>
I have a function to create a pdf which should return bitarray. Below is
Below is an old PHP function I have for a dropdown list for users

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.