Error using sortrows (line 63) COL must be a vector of column indices into X. Error in newton (line 77) vardmy=sor​trows(var,​-1);. what does mean by this error ? how to remove it?

%........ fitness calculation..................
pufmx=vnucsh(n,1)*1.00; % varible constarints on puf
pufmn=vnucsh(n,1)*0.9;
nucsh=[vnucsh(n,1);vnucsh(n,2)];
fitness=fit_fun(nucsh);
if(fitness~=0)
var=[var;fitness;nucsh(1);nucsh(2)]; % calling fitness function
nro=nro+1;
end
end
vardmy=sortrows(var,-1);
vardmy1=vardmy(1,:); % one highest fitness variable
maxvarfit=vardmy1(1); % maximum fitness

 Accepted Answer

In current versions of MATLAB, sortrows with a negative column number means to sort in descending order on that column..
You could do a sortrows(var,1) and then
vardmy1=vardmy(end,:);

4 Comments

still i am getting the same error Error using sortrows (line 63) COL must be a vector of column indices into X.
Error in newton (line 77) vardmy=sortrows(var,1); .Please resolve the error..
var=[var;fitness;nucsh(1);nucsh(2)]; Is that statement is right???
var=[var;fitness;nucsh(1);nucsh(2)];
Should probably be
var=[var;fitness, nucsh(1), nucsh(2)];
However are you absolutely certain that you had at least one nonzero fitness? If all of the fitness values are 0 then you never add anything to var and it would be empty.
sir i run the code and in command window no error is showing. Downwards it is showing busy but from 4 hours it remains same i.e is busy.... what is this means.what should i do??
Sorry, you have not posted enough of the code for me to speculate on the reason.

Sign in to comment.

More Answers (1)

function gsa_nr_method
clear all;
clc;
close all;
global pufmn pufmx xmmn xmmx
global ismx vlmn vlmx
global pmax MRT_55 otprmx
N=50;
max_it=1000;
ElitistCheck=1; Rpower=1;
min_flag=1; % 1: minimization, 0: maximization
F_index=1;
Rnorm=2;
[Fbest,Lbest,BestChart,MeanChart]=GSA(F_index,N,max_it,ElitistCheck,min_flag,Rpower);
Fbest,semilogy(BestChart,'--k')
title(['\fontsize{12}\bf F',num2str(F_index)]);
xlabel('\fontsize{12}\bf Iteration');ylabel('\fontsize{12}\bf Average Best-so-far');
legend('\fontsize{10}\bf GSA',1);
gsa program~
function [Fbest,Lbest,BestChart,MeanChart]=GSA(F_index,N,max_it,ElitistCheck,min_flag,Rpower)
%V: Velocity.
%a: Acceleration.
%M: Mass. Ma=Mp=Mi=M;
%dim: Dimension of the test function.
%N: Number of agents.
%X: Position of agents. dim-by-N matrix.
%R: Distance between agents in search space.
%[low-up]: Allowable range for search space.
%Rnorm: Norm in eq.8.
%Rpower: Power of R in eq.7.
% Rnorm=2;
%get allowable range and dimension of the test function.
[down,up,dim]=test_functions_range(F_index);
%random initialization for agents.
X=initialization(dim,N,up,down);
%create the best so far chart and average fitnesses chart.
BestChart=[];MeanChart=[];
V=zeros(N,dim);
for iteration=1:max_it
% iteration
%Checking allowable range.
X=space_bound(X,up,down);
%Evaluation of agents.
[fitness]=evaluateF(X,F_index)
if min_flag==1
[best, best_X]=min(fitness); %minimization.
else
[best, best_X]=max(fitness); %maximization.
end
if iteration==1
Fbest=best;Lbest=X(best_X,:);
end
if min_flag==1
if best<Fbest %minimization.
Fbest=best;Lbest=X(best_X,:);
end
else
if best>Fbest %maximization
Fbest=best;Lbest=X(best_X,:);
end
end
BestChart=[BestChart Fbest]
MeanChart=[MeanChart mean(fitness)]
%Calculation of M. eq.14-20
[M]=massCalculation(fitness,min_flag);
%Calculation of Gravitational constant. eq.13.
G=Gconstant(iteration,max_it);
%Calculation of accelaration in gravitational field. eq.7-10,21.
Rnorm=2;
a=Gfield(M,X,G,Rnorm,Rpower,ElitistCheck,iteration,max_it);
%Agent movement. eq.11-12
[X,V]=move(X,a,V);
end %iteration
I am getting this error again and again but unable to understand the error between these.....please help
Error in gsa_nr_method (line 40)
[Fbest,Lbest,BestChart,MeanChart]=GSA(F_index,N,max_it,ElitistCheck,min_flag,Rpower);

7 Comments

There is no sortrows() in this code. Perhaps there is in some of the code you did not post. Please post the complete error message, and all of the functions.
program is long.Is it feasible to add whole program on this platform?
You can zip it up and attach the zip file, as long as the zip file is no more than 5 megabytes.
Other people can see it. If you need your code to be private, you should hire a consultant.
Yes, it costs something; depending on who you hire, it could end up costing a lot. That is the price of privacy.
The volunteers here donate their time to benefit everyone, expecting that the questions and answers will be public so that everyone can learn from them and everyone can contribute. However, the volunteers often decline to answer private questions as private questions get into "work" and people expect to be paid for work.
I am not sure who is available as a consultant these days. Yair possibly -- but Yair is a professional and expects to be paid for private professional services. Some of the more active volunteers might agree to being hired, if the topic interests them and they do not have anything else to do. I am not accepting contracts these days.
Mathworks offers a consulting service; I do not know how much they charge.
You can probably find MATLAB consulting services online, possibly even close to you. I would suggest, though, that if you hire one of the "5 dollars for any program" services that you should not trust that your code will stay confidential.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!