loop for different columns

Hi every one
i want to write a loop but i get confused
i have a data with 103 rows and 811 columns. i want calculate 6 parameters for all the columns. at last i should have a matrix with 811 rows and 6 parameters. please help me. i know that i cant find the right position of the counter n trough the loop.
Y1='Y1.xlsx'
Y1=xlsread(Y1);
z2_real=Y1(:,1);
threshold = 4;
N=size(Y1,2);
n=1
for i=1:N
Y1_new(:,n)=Y1;
[r_z2_real,c_z2_real]=size(z2_real);
[rows_rl, columns_rl] = find(z2_real > threshold);%number of real active cmpds [rows_tn, columns_tn] = find(Y1 > threshold);%number of predicted as active cmpds [rows_rl_tp, columns_rl_tp] = find(z2_real < threshold);%number of real inactive cmpds [rows_tp, columns_tp] = find(Y1 < threshold);%number of predicted as inactive cmpds NTN = nnz(ismember(rows_tn,rows_rl));%NTN:number of correct active cmpd NTP = nnz(ismember(rows_tp,rows_rl_tp));%NTP:number of correct inactive cmpd FC=((NTN+NTP)/r_z2_real)*280; [rr_rows_rl_tp,cc_rows_rl_tp]=size(rows_rl_tp); [rr_rows_tp,cc_rows_tp]=size(rows_tp); NFP=abs(rr_rows_tp-NTP);%NFP:number of cmpds that model determined as actice cmpd incorrectly FAR=((NFP/(NTN+NTP))*280); [rr_rows_rl,cc_rows_rl]=size(rows_rl); [rr_rows_tn,cc_rows_tn]=size(rows_tn); NFN=abs(rr_rows_rl-NTN);%NFP:number of cmpds that model determined as inactice cmpd incorrectly POD=(NTP/(NFN+NTP))*280;
[rows_tn, columns_tn] = find(Y1_new > threshold);%number of predicted as active cmpds
[rows_rl_tp, columns_rl_tp] = find(z2_real < threshold);%number of real inactive cmpds
[rows_tp, columns_tp] = find(Y1_new < threshold);%number of predicted as inactive cmpds
NTN = nnz(ismember(rows_tn,rows_rl));%NTN:number of correct active cmpd
NTP = nnz(ismember(rows_tp,rows_rl_tp));%NTP:number of correct inactive cmpd
FC=((NTN+NTP)/r_z2_real)*100;
[rr_rows_rl_tp,cc_rows_rl_tp]=size(rows_rl_tp);
[rr_rows_tp,cc_rows_tp]=size(rows_tp);
NFP=abs(rr_rows_rl_tp-rr_rows_tp);%NFP:number of cmpds that model determined as actice cmpd incorrectly
FAR=((NFP/(NTN+NTP))*100);
[rr_rows_rl,cc_rows_rl]=size(rows_rl);
[rr_rows_tn,cc_rows_tn]=size(rows_tn);
NFN=abs(rr_rows_rl-NTN);%NFP:number of cmpds that model determined as inactice cmpd incorrectly
POD=(NTP/(NFN+NTP))*100;
ss(n,:)=[NTN,NTP,NFP,NFN,FC,FAR,POD];
ss(isnan(ss))=0;
% i=i+1
xlswrite('classification_results.xlsx',ss,'results');
end
%

 Accepted Answer

xlswrite('classification_results.xlsx',ss,'results');
You are always writing the ss vector of results to the same location in the file.
Change
% i=i+1
xlswrite('classification_results.xlsx',ss,'results');
end
to
all_ss(i, :) = ss;
end
xlswrite('classification_results.xlsx', all_ss, 'results');

2 Comments

mary moz's incorrectly posted and accepted "Answer" moved here:
Thanks for the reply. but the problem is still exist. i get the following error.
Subscripted assignment dimension mismatch.
Error in parameters (line 9)
Y1_new(i, :) = Y1
Dear Walter
it works by your guidance using following code. thanks
clc
clear all
Y1='Y1.xlsx'
Y1=xlsread(Y1);
z2_real=Y1(:,1);
threshold = 4;
N=size(Y1,2);
n=1
for i=1:N
Y1_new = Y1(:,i)
[r_z2_real,c_z2_real]=size(z2_real);
[rows_rl, columns_rl] = find(z2_real > threshold);%number of real active cmpds [rows_tn, columns_tn] = find(Y1 > threshold);%number of predicted as active cmpds [rows_rl_tp, columns_rl_tp] = find(z2_real < threshold);%number of real inactive cmpds [rows_tp, columns_tp] = find(Y1 < threshold);%number of predicted as inactive cmpds NTN = nnz(ismember(rows_tn,rows_rl));%NTN:number of correct active cmpd NTP = nnz(ismember(rows_tp,rows_rl_tp));%NTP:number of correct inactive cmpd FC=((NTN+NTP)/r_z2_real)*280; [rr_rows_rl_tp,cc_rows_rl_tp]=size(rows_rl_tp); [rr_rows_tp,cc_rows_tp]=size(rows_tp); NFP=abs(rr_rows_tp-NTP);%NFP:number of cmpds that model determined as actice cmpd incorrectly FAR=((NFP/(NTN+NTP))*280); [rr_rows_rl,cc_rows_rl]=size(rows_rl); [rr_rows_tn,cc_rows_tn]=size(rows_tn); NFN=abs(rr_rows_rl-NTN);%NFP:number of cmpds that model determined as inactice cmpd incorrectly POD=(NTP/(NFN+NTP))*280;
[rows_tn, columns_tn] = find(Y1_new > threshold);%number of predicted as active cmpds
[rows_rl_tp, columns_rl_tp] = find(z2_real < threshold);%number of real inactive cmpds
[rows_tp, columns_tp] = find(Y1_new < threshold);%number of predicted as inactive cmpds
NTN = nnz(ismember(rows_tn,rows_rl));%NTN:number of correct active cmpd
NTP = nnz(ismember(rows_tp,rows_rl_tp));%NTP:number of correct inactive cmpd
FC=((NTN+NTP)/r_z2_real)*100;
[rr_rows_rl_tp,cc_rows_rl_tp]=size(rows_rl_tp);
[rr_rows_tp,cc_rows_tp]=size(rows_tp);
NFP=abs(rr_rows_rl_tp-rr_rows_tp);%NFP:number of cmpds that model determined as actice cmpd incorrectly
FAR=((NFP/(NTN+NTP))*100);
[rr_rows_rl,cc_rows_rl]=size(rows_rl);
[rr_rows_tn,cc_rows_tn]=size(rows_tn);
NFN=abs(rr_rows_rl-NTN);%NFP:number of cmpds that model determined as inactice cmpd incorrectly
POD=(NTP/(NFN+NTP))*100;
ss(:,i)=[NTN,NTP,NFP,NFN,FC,FAR,POD];
ss(isnan(ss))=0;
% all_ss(i) = ss;
end
xlswrite('classification_results.xlsx', ss', 'results');

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!