I have two matrices. The x(r,i,t1,t2) and y(t1) matrix. I want to multiply the matrix y in matrix x for all r, i, and t2. I have the following codes and errors. Could you please help me to realize what is the problem.
R=8;
I=12;
T1=11;
T2=10;
x=rand(R,I,T,TT);
y =[99 129 115 128 96 94 98 107 133 99 120];
for r=1:R
for i=1:I
for t2=1:T2
for t1= 1: T1
xnew(r,i,t1,t2)=y(t1).*x(r,i,t1,t2);
end
end
end
end
Error
Undefined function 'y' for input arguments of type 'double'.
Error in test (line 12)
xnew(r,i,t1,t2)=y(t1).*x(r,i,t1,t2);

6 件のコメント

Walter Roberson
Walter Roberson 2016 年 11 月 21 日
Does it literally say class "y" ? What is your y?
which -all y
rezi raf
rezi raf 2016 年 11 月 21 日
編集済み: Walter Roberson 2016 年 11 月 21 日
@Walter, y is a matrix or vector of the variable t1.
For example if T1=4 the y is a 1 by 4 matrix like [20,30,42,15].
However for example x is a 3*5*4*6 matrix when R=3, I=5, T1=4, and T2= 6.
Walter Roberson
Walter Roberson 2016 年 11 月 21 日
Please copy and paste the exact error message. Please also show the output of
which -all y
rezi raf
rezi raf 2016 年 11 月 21 日
編集済み: rezi raf 2016 年 11 月 21 日
@ Walter, I do not know what you mean by the output of which -all y. Could you please explain that? This is the code and exact error:
R=8;
I=12;
T1=11;
T2=10;
x=rand(R,I,T,TT);
y =[99 129 115 128 96 94 98 107 133 99 120];
for r=1:R
for i=1:I
for t2=1:T2
for t1= 1: T1
xnew(r,i,t1,t2)=y(t1).*x(r,i,t1,t2);
end
end
end
end
Error
Undefined function 'y' for input arguments of type 'double'.
Error in test (line 12)
xnew(r,i,t1,t2)=y(t1).*x(r,i,t1,t2);
Walter Roberson
Walter Roberson 2016 年 11 月 21 日
That line of code is not at line 12 of what you have posted -- not unless exactly two out of the three blank lines are not actually present in your code.
Walter Roberson
Walter Roberson 2016 年 11 月 21 日
After you run your code and get the failure about y, go to the command line and type in
which -all y
and show us the result.
Also please tell us which MATLAB version you are using.
Please also attach your code as a .m file as your code is not the same as you have posted (your posted code does not define T, and the line numbers are not right for what you posted.)

サインインしてコメントする。

 採用された回答

the cyclist
the cyclist 2016 年 11 月 21 日

0 投票

If I replace
x=rand(R,I,T,TT);
with
x=rand(R,I,T1,T2);
your code runs to completion for me.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2016 年 11 月 20 日

コメント済み:

2016 年 11 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by