Assign different input using for loop
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
This is probably a simple question for most of you but I've been struggling with it for far too long. I have several lines of codes which will eventually get an output(O). When I only use a single input(in), the codes work fine but let's say I want to use a vector as an input and get an output with the same size as the input vector (each value in input vector will get corresponding output), how should I go about it? I've tried using for loop but no luck.
%%Loading variables
weight = unifrnd(-10, 10, [1 13]);
W1 = weight(1,1:4); % Input Layer Weight
W2 = weight(1,5:8); % Input Layer Bias
W3 = weight(1,9:12) % Hidden Layer Weight
W4 = weight(1,13); % Hidden Layer Bias
I.I = W1.*in % Input x weight
I.B = W2; % Bias
H.SUM = I.I+I.B; % Hidden Neuron
H = tansig (H.SUM) % Hidden Neuron Squashed
O.SUM = dot(H,W3') + W4 % Hidden Neuron x Weight + Bias
O = purelin (O.SUM) % Output Neuron
댓글 수: 0
답변 (1개)
Rahul Kalampattel
2017년 2월 15일
편집: Rahul Kalampattel
2017년 2월 15일
I edited three lines (the commented out ones), the code now allows you to enter a row vector of inputs and returns a row vector of outputs. The variables I.I and I.B are now matrices; you could do achieve the same result with for loops, but I think it's faster this way.
%%Loading variables
weight = unifrnd(-10, 10, [1 13]);
W1 = weight(1,1:4); % Input Layer Weight
W2 = weight(1,5:8); % Input Layer Bias
W3 = weight(1,9:12); % Hidden Layer Weight
W4 = weight(1,13); % Hidden Layer Bias
%I.I = W1.*in
I.I = W1'*in % Input x weight
%I.B = W2
I.B = repmat(W2',1,length(in)) % Bias
H.SUM = I.I+I.B % Hidden Neuron
H = tansig (H.SUM) % Hidden Neuron Squashed
%O.SUM = dot(H,W3') + W4
O.SUM = W3*H + W4 % Hidden Neuron x Weight + Bias
O = purelin (O.SUM) % Output Neuron
댓글 수: 2
Rahul Kalampattel
2017년 2월 17일
편집: Rahul Kalampattel
2017년 2월 17일
data = xlsread('testSpreadsheet');
Once you've done that, you can transpose columns into rows with
data = data';
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!