how to solve this, Error using .* Arrays have incompatible sizes for this operation. Error in Elm (line 156) tempH_test​=InputWeig​ht.*TV.P;

1 view (last 30 days)
i have problem in ELM's code for classification. anybody can solve this?
Error using .*
Arrays have incompatible sizes for this operation.
Error in Elm (line 156)
tempH_test=InputWeight.*TV.P;

Answers (1)

Walter Roberson
Walter Roberson on 28 May 2023
The .* (element-by-element multiplication) operator can proceed in the case where:
  • every dimension that is not 1 in either InputWeight or TV.P, is the same between the two
  • every dimension that is 1 in either InputWeight or TV.P is permitted to be any value in the other, and the length 1 will be replicated internally as many times as needed to match the other value
Because trailing dimensions are considered to have length 1, this does permit, for example, a 1024 x 768 matrix to be .* with a 1024 x 768 x 3 matrix -- the 1024 x 768 is implicitly 1024 x 768 x 1 so the rule of "you can have a mismatch if the length is 1" works out.
You could .* between 1024 x 1 vector and a 1 x 768 vector -- the implied replication can take place in both variables as needed.
What you cannot do is, for example, 1024 x 768 .* 1280 x 768. The 1024 is not 1 and does not match the 1280 that is not 1, so such a multiplication would be an error.
One of the more common ways this error occurs is if an RGB image is input but the code assumes that it was a grayscale image, especially if the code does something along the lines of
[numrows, numcols] = size(TheImage);
when TheImage is RGB this would result in a misleading value being stored in numcols.

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!