Problem computing array,  ??? Error using ==> times  Matrix dimensions must agree

Posted on 2009-02-23
Last Modified: 2013-11-25
Hi all,
I am having a problem computing a 1 dimensional matrix, whose elements are made up of sums of one 1-dimensional matrix dot multiplied by one column of a 2-dimensional matrix. Please see the code snippet if this sounds confusing. Why am I getting this error,

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

Error in ==> ncorr2 at 11

Keep in mind that I would call this function like so:
x1 = [1;2;3]
x2 = [4;5;6]
[corr, lags] = ncorr2(x1,x2)

Thanks for all of your help and let me know if I need to be more specific or add any information!
function [corr, lags] = ncorr2(x1, x2)










Open in new window

Question by:ehensens
    LVL 15

    Accepted Solution

    When you do by-element muiltiplication, both matrices should have the same size.
    If you want to miltiply vector a to all columns of b, just repeat a to have the same number of columns as in b.

    Open in new window


    Author Closing Comment

    Once again, great job.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    sumNumber challenge 16 79
    sum13 challenge 24 69
    has12 challenge 13 52
    countHi2 challenge 7 30
    Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now