Error with Sortrow function in Matlab R2016b

1 view (last 30 days)
I have 310 data files which are in .cmn format. Each file consists of few paramters, on which the data is collected. When I execute the code in Matlab R2016b, I got the follwoing error, which is as follows.
Error using sortrows (line 62)
COL must be a vector of column indices into X.
Error in sample (line 22)
Cs = sortrows(x,2);
Note: Orginally, the code was written and executed in Matlab R2015, where the code has run successfully and the outputs were shown. Right now, because of unavailiablity of Matlab R2015 version, I am executing the code in Matlab R2016b version. Will this be one of the possible reasons for getting the error? Does Matlab version effect the exection of code? If not, please suggest me a way to clear the error. As per my knowledge, there might be problem with the sortrow function. Please let me know if I am wrong.
  • Note: Here is the code attached below. Kindly please make a look over it.
  • Note Imp:I am also attaching the screenshot of one file being used, as a sample, to let u know the format of data.
clc;
clear all;
close all;
FileList = dir('*.Cmn');
N = size(FileList,1);
for k = 1:N %get the file name:
filename1{k}= FileList(k).name;
disp(filename1);
end
% In sprintf(‘name of the first file of the year in the folder’)
for k = 1:N,
filename=filename1{k};
myfilename = sprintf('SCND004-2016-01-04%d.Cmn', k);
mydata{k} = importdata(filename);
end
%TEC processing
AA=[]
for i=1:N,
x=mydata{:,i};
Cs = sortrows(x,2);
idx=find(Cs(:,2)>0);
CC=Cs(idx,:);
C1=CC(:,9);
en=C1(1:end/24);
en1=C1(1:end);
cc=length(en1);
cc1=13750-cc;
b = cat(1, C1, zeros(cc1, 1));
c = reshape(b,550,25);
C=mean(c) ;
C=C(:,1:24);
AA=[AA C];
End
AIT2016=reshape(AA,24,N);
singleTec=AIT2016(:,2)
% In place of 2 event day can be replaced so can observe for desired day
plot (AIT2016);
save ('AIT2016','AIT2016'); % AIT2017 for 2017 Data
  3 Comments
mounica penmetsha
mounica penmetsha on 9 Apr 2019
I would like to thank you for the quick reply @Walter Roberson. If you don't mind, could you please help me a way, to solve the above error.
Guillaume
Guillaume on 9 Apr 2019
Note that the problem has nothing to do with your version of matlab. It's a bug in your code that you're only finding now because one of the input file is somehow different from the previous files you've used.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 9 Apr 2019
Code attached, rewritten to use tables and simplified. Requires R2013b or later.
  4 Comments
mounica penmetsha
mounica penmetsha on 10 Apr 2019
Thank you @Guillaume. The error has been resolved.

Sign in to comment.

More Answers (1)

Jan
Jan on 9 Apr 2019
Edited: Jan on 9 Apr 2019
Start with omitting the brute clearing header:
clc;
clear all;
close all;
It is a waste of time to kill everything. Better use functions to keep the workspace clean. All you need is to start the code with the keyword "function".
Now add this line:
x=mydata{:,i}; % from your code
if size(x, 2) < 2
fprintf(2, '%s contains unexpected data\n', filename1{k});
continue;
end
By the way, this can be simplified:
N = size(FileList,1);
for k = 1:N %get the file name:
filename1{k}= FileList(k).name;
disp(filename1);
end
to
filename1 = {FileList.name};
fprintf('%s\n', filename1{:});

Tags

Community Treasure Hunt

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

Start Hunting!