简体   繁体   English

从Matlab中的两个不同文件夹加载文件

[英]load files from two different folders in matlab

Hi and I am little bit new in matlab. 您好,我在Matlab中有点陌生。 I have two different folders in my laptop, each one contains about 400 different files. 我的笔记本电脑中有两个不同的文件夹,每个文件夹包含约400个不同的文件。 I want to load all these files (400 from first folder and 400 from second folder), I tried like that but doesn't work: 我想加载所有这些文件(第一个文件夹中的400个文件,第二个文件夹中的400个文件),我尝试这样做,但不起作用:

folder1=('E:\results\1\'); 
folder2=('E:\results\2\'); 
data=load([folder1,'*.m']);
data1=load([folder2,'*.m']);

and then I want to take first file from folder1 and subtracted from first file from folder1 and save it in new folder. 然后我要从folder1提取第一个文件,并从folder1的第一个文件中减去,然后将其保存在新文件夹中。 and do that for all other files ... etc can some expert give me any suggerstion!! 并针对所有其他文件执行此操作...等一些专家可以给我任何建议!! thanks in advance. 提前致谢。

Pretty sure load takes one file at a time. 可以肯定, load需要一个文件。 Try a simple variant like this: 尝试这样的简单变体:

folder1=('E:\results\1\'); 
folder2=('E:\results\2\');
files1 = dir( [folder1,'*.m'] );
files2 = dir( [folder2,'*.m'] );

data = cell(length(files1),1);  % I don't know what's in the mat files, but let's start with a cell array
data1 = cell(length(files2),1);
for ii=1:length(files1)
  data{ii} = load(fullfile(folder1,files1(ii).name));
end
for ii=1:length(files2)
  data1{ii} = load(fullfile(folder2,files2(ii).name));
end

There are other, more one liner ways, but this is a fairly pedantic. 还有其他一种以上的班轮方式,但这是一个很老套的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在MATLAB中从两种不同类型的目录加载所有文件 - How to load all files from a directory of two different types in MATLAB 将循环中的输出保存在Matlab中的不同文件夹中 - saving outputs from a loop in Matlab in different folders 从Matlab中的不同文件夹中读取多个图像 - read multiple images from different folders in matlab 从两个不同的文件访问Matlab中的同一串行端口对象 - Accessing same Serial Port object in Matlab from two different files 如何在两台计算机上使用matlab并在脚本中加载文件(位于不同的文件位置)? - How do I use matlab on two computers and load files (located in different file locations) in my script? 使用一个脚本从不同文件夹运行不同的 matlab 脚本 - running different matlab scripts from different folders by using one script 从不同的matlab文件中绘图 - Plotting from different matlab files 从differente文件夹读取xls文件并在MATLAB上编写 - Read xls files from differente folders and write on MATLAB Matlab:来自具有不同概率的文件夹的随机刺激列表 - Matlab: Random list of stimuli from folders with different probabilities MATLAB:打开和编辑嵌套在文件夹中的文件夹中的文件 - MATLAB: Opening and Editing Files nested in folders in folders
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM