Clear Filters
Clear Filters

issue while concatenating the matrix

1 view (last 30 days)
Arvind Gauns
Arvind Gauns on 30 Jun 2022
Commented: KSSV on 30 Jun 2022
This is the code which I am using
%%
clear all
clc
[file_list, path_n] = uigetfile('final*.mat', 'Grab all the files', 'MultiSelect','on');
if ischar(file_list); file_list = {file_list}; end %only one selected
if ~iscell(file_list); return; end %user cancel
ii=1
for i = 1:length(file_list)
this_file = fullfile(path_n, file_list{i});
loadfile = load(this_file);
s = struct(loadfile);
h = loadfile.o2a_s ;
jj = h(:,1);
z = datenum(h(:,2),'HH:MM');
h(:,2)=[];
KK = str2double(h);
%finding ths number of rows and columns
[R C]=size(KK);
% assigning a zero matrix gg of the given size
gg=zeros(1,5);
%% everything is working fine as per needed till here but from here i am facing troubles
j=1;
for ii=1:(R-1);
%%
if z(ii,1)>= [738522.558] while z(ii,1)<= [738522.566]
gg=[gg;KK(ii,:)];
end
end
end
end
% dd(1,:) = [];
the files are in Mat format. the file type is string.
i want values of z in such manner z(ii,1)>= [738522.558] while z(ii,1)<= [738522.566]
the problem is the code is running fine but ti am not able to retrieve the gg matrix at the end. ( rather i am getting the values corresponding to the last file inputted to the loop)
2. I want to include the file name corresponding to the ii value in the gg matrix. how to modify the code for the same ?
  2 Comments
Stephen23
Stephen23 on 30 Jun 2022
if isnumeric(file_list)
return
end
file_list = cellstr(file_list);

Sign in to comment.

Accepted Answer

KSSV
KSSV on 30 Jun 2022
Edited: KSSV on 30 Jun 2022
[file_list, path_n] = uigetfile('final*.mat', 'Grab all the files', 'MultiSelect','on');
if ischar(file_list); file_list = {file_list}; end %only one selected
if ~iscell(file_list); return; end %user cancel
N = length(file_list) ;
iwant = cell(N,1) ;
for i = 1:N
this_file = fullfile(path_n, file_list{i});
loadfile = load(this_file);
s = struct(loadfile);
h = loadfile.o2a_s ;
jj = h(:,1);
z = datenum(h(:,2),'HH:MM');
h(:,2)=[];
KK = str2double(h);
%finding ths number of rows and columns
[R, C]=size(KK);
% assigning a zero matrix gg of the given size
gg=zeros(1,5);
%% everything is working fine as per needed till here but from here i am facing troubles
j=1;
for ii=1:(R-1)
if z(ii,1)>= 738522.558
while z(ii,1)<= 738522.566
gg=[gg;KK(ii,:)];
end
end
end
iwant{i} = gg ;
end
You already have files names in hand.
  2 Comments
Arvind Gauns
Arvind Gauns on 30 Jun 2022
gg=[]; %zeros(1,5);
%% everything is working fine as per needed till here but from here i am facing troubles
j=1;
for ii=1:(R-1)
if z(ii,1)>= 738522.559
if z(ii,1)<= 738522.565
gg=[gg;KK(ii,:)];
end
end
end
iwant{i} = gg ;
end
with a little modification, it worked.
Thanks.
KSSV
KSSV on 30 Jun 2022
Thanks is accepting/ voting the answer... :)

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!