I am getting an error "Variable a must be of data type char. It is currently of type double. Check where the variable is assigned a value."

27 ビュー (過去 30 日間)
Chloe
Chloe 2024 年 2 月 13 日
回答済み: Pratik 2024 年 2 月 13 日
Question:
Using matrix multiplication, multiply A1 by A1, set to a
Using matrix multiplication, multiply v1 by A1, set to c
Input: A1 = [-2:1; 1:-1:-2; -2:2:4]
v1 = linspace(-2,4,4)
a = A1 .* A1
c = v1 .* A1
output:
Variable a must be of data type char. It is currently of type double. Check where the variable is assigned a value.

回答 (1 件)

Pratik
Pratik 2024 年 2 月 13 日
Hi Chloe,
In my understanding, you want to perform matrix multiplication between A1 & A1 , v1 & A1. The operator to perform matrix multiplication is '*' or function ‘mtimes’. Operator '.*' performs element wise multiplication.
I was not able to reproduce the error mentioned in the question with the code provided.
A1 = [-2:1; 1:-1:-2; -2:2:4]
A1 = 3×4
-2 -1 0 1 1 0 -1 -2 -2 0 2 4
v1 = linspace(-2,4,4)
v1 = 1×4
-2 0 2 4
a = A1 .* A1
a = 3×4
4 1 0 1 1 0 1 4 4 0 4 16
c = v1 .* A1
c = 3×4
4 0 0 4 -2 0 -2 -8 4 0 4 16
For matrix multiplication of matrices A and B, the number of columns of A must equal the number of rows of B.
Please refer to the documentation of “mtimes” for more information on matrix multiplication:
Please refer to the documentation of “times” for more information on element wise multiplication:
I hope this helps!

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by