what is wrong with the following code, i get the following massege :Subscripted assignment dimension mismatch. Error in Untitled3 (line 14) y2(i)=purelin(y22);
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
clc; clear all;
a=[1 2 3; 20 21 22]
b=[1 2 3; 4 5 6; 7 8 9]
w1=[4 1 5;2 5 0;6 7 10]
w2=[10 11 12; 30 1 0]
b1=[0.4; 0.2; 0.7]
b2=[0.005; 0.01]
L=length(a)
for i=1:L
x=b(:,i);
y1=w1*x+b1;
y1=tansig(y1);
y22=w2*y1+b2;
y2(i)=purelin(y22);
end
0 comentarios
Respuestas (6)
dpb
el 31 de Dic. de 2018
...
x=b(:,i);
y1=w1*x+b1;
y1=tansig(y1);
y22=w2*y1+b2;
where
b --> 3x1
b1 --> 3x1
b2 --> 2x1
w1 --> 3x3
w2 --> 2x3
y1 --> 3x3 X 3x1 --> 3x1
y22--> 2x3 X 3x1 --> 2x1
ergo
purelin(y22) --> 2x1
and you can't put two things into one index locations.
0 comentarios
Mary Abdu
el 31 de Dic. de 2018
1 comentario
Walter Roberson
el 31 de Dic. de 2018
Without our seeing that other code it is difficult for us to give you a meaningful solution.
Walter Roberson
el 1 de En. de 2019
Editada: Walter Roberson
el 1 de En. de 2019
We would need to know the size of w, and the size and type of inputs and outputs. It is not clear why you multiply w by 1 ?
Assuming your input w is a row vector, then:
Your w1 could be constructed as
w1 = reshape(w(1:52*N), N, []);
(Yes, it is that simple.)
Now for
y2(1,i)=purelin(w2(1,:)*(tansig(w1*in(1,i)+b1))+b2(1,:));
- w2 is constructed as 2 x N
- w1 is N x 52
- b1 is N x 1 because it is constructed from the transpose of 1 x N
- b2 is 2 x N so b2(1,:) is 1 x N
So (tansig(w1*in(1,i)+b1)) is N x 52 + N x 1. That would be an error up to R2016a, but in R2016b became well defined as giving N x 52.
w2(2,:) would be 1 x N. With the tansig returning N x 52, that would give (1 x N) * (N * 52), which is valid and gives 1 x 52. Then purelin() applied to 1 x 52 would give 1 x 52.
So the right hand side is 1 x 52, and you are trying to store that into a 1 x 1 storage location.
2 comentarios
Walter Roberson
el 5 de En. de 2019
If you need the answer to be a scalar then you will need to talk to us about how you want the formulas changed. Otherwise, use techniques such as
y2(1,i,:)=purelin(w2(1,:)*(tansig(w1*in(1,i)+b1))+b2(1,:));
madhan ravi
el 1 de En. de 2019
clc; clear all;
a=[1 2 3; 20 21 22]
b=[1 2 3; 4 5 6; 7 8 9]
w1=[4 1 5;2 5 0;6 7 10]
w2=[10 11 12; 30 1 0]
b1=[0.4; 0.2; 0.7]
b2=[0.005; 0.01]
L=length(a);
y2=cell(1,L); % preallocate as cell
for i=1:L
x=b(:,i);
y1=w1*x+b1;
y1=tansig(y1);
y22=w2*y1+b2;
y2{i}=purelin(y22);
end
celldisp(y2)
[y2{:}] % double array
3 comentarios
madhan ravi
el 4 de En. de 2019
Editada: madhan ravi
el 4 de En. de 2019
you help us to help you , "still not working with me" - is completely useless , what error messgae did you get ?
Upload t and y as .mat file
Mary Abdu
el 1 de En. de 2019
1 comentario
madhan ravi
el 1 de En. de 2019
Editada: madhan ravi
el 1 de En. de 2019
See the comment in my answer , please make a comment on the answer instead of adding answers , thank you for understanding.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!