MATLAB Answers

Extract rows from table to input into new table

1 view (last 30 days)
Camila Gill
Camila Gill on 21 Apr 2020
Edited: Asvin Kumar on 19 May 2020
Data attached.
I have the following neural network that prints a table of results. I need to extract specific rows (with all the data in the row) and combine them into a new table. The rows needed are found based on the values in the first three rows.
Example extract row with the integers: (3 5 4) or (5 4 5) (number in each column)
clear
load 'beam_designs_lhs100.mat'; % beam_designs
% Normalize beam models and responses
[beamsin, PS] = mapminmax(beam_designs(:,1:5)');
[beamsout, TS] = mapminmax(beam_designs(:,6:7)');
count = 1; % define a counter
count2 = 1;
% 3-layer network
for l1 = 3:5
for l2 = 3:5
for l3 = 3:5
% Divide designs into training and test datasets
trainin = beamsin(:,1:600);
trainout = beamsout(:,1:600);
testin = beamsin(:,600+1:end);
testout = beamsout(:,600+1:end);
% Create function fitting neural network
net = fitnet([l1,l2,l3], 'trainlm');
netbr = fitnet([l1,l2,l3], 'trainbr');
net.divideParam.trainRatio = 1;
net.divideParam.valRatio = 0;
net.divideParam.testRatio = 0;
% Train the NN and evaluate its performance
[net, tr] = train(net, trainin, trainout);
[netbr, tr] = train(netbr, trainin, trainout);
outputsD = net(testin(1:5,:));
outputsB = netbr(testin(1:5,:));
% perf = perform(net, testout, outputsD); % or use sum of squares
% Computes the sum of squared errors and print results
err_defD(count) = sum((testout(1,:) - outputsD(1,:)).^2);
err_defB(count) = sum((testout(1,:) - outputsB(1,:)).^2);
count = count+1;
err_volD(count2) = sum((testout(2,:) - outputsD(2,:)).^2);
err_volB(count2) = sum((testout(2,:) - outputsB(2,:)).^2);
count2 = count2+1;
end
end
end
% Table of results
l = 3; u = 5;
v = repmat(l:u,(u-l)+7,1);
v = v(1:end);
NumNeurons1stLayer = [v]';
% l = 3; u = 5;
% v2 = repmat(l:u,(u-l)+1,3);
% v2 = v(1:end);
lu = (l:u)';
v2 = repmat(lu,(u-l)+1,3)
v2 = reshape(v2', [1,27])
NumNeurons2ndLayer = [v2]';
lu = (l:u)';
v3 = repmat(lu,(u-l)+7,1);
NumNeurons3rdLayer = v3;
DefaultDeflectionErr = (err_defD)';
BayesianDeflectionErr = (err_defB)';
DefaultVolumeErr = (err_volD)';
BayesianVolumeErr = (err_volB)';
% BestPerfomance =
% EpochNum =
T = table(NumNeurons1stLayer,NumNeurons2ndLayer,NumNeurons3rdLayer,DefaultDeflectionErr,BayesianDeflectionErr,...
DefaultVolumeErr, BayesianVolumeErr)

  0 Comments

Sign in to comment.

Answers (1)

Asvin Kumar
Asvin Kumar on 19 May 2020
Edited: Asvin Kumar on 19 May 2020
You can do this with ismember and logical operators.
ind1 = ismember(T.Var1,[3 5]) ;
ind2 = ismember(T.Var2,[5 4]);
ind3 = ismember(T.Var2,[4 5]);
T2 = T{ind1 & ind2 & ind3,:};
The ismember function is used to find the locations of the values in the columns.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!