1.合并两个矩阵
a = [1 2 3;4 5 6]
b = [7 8 9;1 2 3]
c = [a,b] %按行(横向)合并
c = [a;b] %按列(纵向)合并
2.合并多个矩阵
clc
clear
temp = dir(['D:\文件夹\','*.txt']);
N = length(temp);
for i = 1:N %先读取文件内所有文件
data = load(temp(i).name);
s = ['a' int2str(i) '=data;'];
eval(s);
end
data_merger_all = {}; %将所有读取的文件放到一个胞元数组中
for j = 1:N
s = ['a' int2str(j)];
data_merger = eval(s);
data_merger_all{j,1} = data_merger;
end
data_end = []; %读取胞元数组数据并进行合并数据操作
for m = 1:2:N-1
n = m + 1;
data1 = data_merger_all{m,1};
data2 = data_merger_all{n,1};
data_end1 = [data1;data2];
data_end = [data_end;data_end1]; %data_end 就是合并之后的数据
end
data_end = [data_end;data_merger_all{N,1}]; %如果N是奇数则需要再加一下这个代码,因为前面N-1及m+1最多只能到偶数
w = "ok"
Hi,科研大神,厌倦了某宝的Chat账号总是封号失联吗?需要稳定的单独账号吗?联系下方企鹅号走起来,都是科研人为大家做点有意义的事情,为您的科研助力~