Assign different input using for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Rahul Kalampattel
am 15 Feb. 2017
Bearbeitet: Rahul Kalampattel
am 15 Feb. 2017
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 Kommentare
Rahul Kalampattel
am 17 Feb. 2017
Bearbeitet: Rahul Kalampattel
am 17 Feb. 2017
data = xlsread('testSpreadsheet');
Once you've done that, you can transpose columns into rows with
data = data';
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!