dbhole.mat contains 334 files. each files consists of [2xn] data. i sort these files with name starting with 'd' and fixed 'h2'. if h2 is not fixed, then what will be the code for doing this?

1 次查看(过去 30 天)
selectedvariables = sprintfc('d%dh2', 1:14);
[~, location] = ismember(selectedvariables, fieldnames(s));
c = struct2cell(s);
c = c(location);
if h2 is not fixed. i want to sort each 'd'followed by numeric and each 'h' followed by numeric
  4 个评论
MUKESH VIKRAM
MUKESH VIKRAM 2016-7-1
编辑:Walter Roberson 2016-7-1
i had used another code , but i does not show exact result which i want.
for i=1:14
for j=1:16
data_2hole{i}=mat2cell(eval(['d',num2str(i),'h',num2str(j)]),length(eval(['d',num2str(i),'h',num2str(j)])));
data= (data_2hole{j,i}{1,1}')
end
end
please tell me how to run all the 'h' contained in each d

请先登录,再进行评论。

回答(1 个)

Thorsten
Thorsten 2016-6-30
I would organise the data into a 2D cell data{}{} and work with this structure.
load dbhole.mat
W = whos('d*h*');
for i = 1:numel(W)
name = W(i).name;
idx = sscanf(name,'d%dh%d');
cmd = sprintf('data{%d}{%d} = %s;', idx(1), idx(2), name);
disp(cmd)
eval(cmd)
end
% plot the data
for i = 1:numel(data), plot(data{i}{1}), hold on, end

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by