HOW CAN I CREATE A MATRIX FILE FROM 3 EXCEL FILES
1 次查看(过去 30 天)
显示 更早的评论
For example I have three excel files
File1
1 2 3
4 5 6
7 8 9
File2
10 11 12
13 14 15
16 17 18
File3
19 20 21
22 23 24
25 26 27
I want to create matrices in form of
1 10 0
-10 19 0
0 0 0
2 11 0
-11 20 0
0 0 0
3 12 0
-12 21 0
0 0 0 .......and so on. help me with this. Consider this matrix as a tensor for every point in a body. I have to multiply these matrices with another matrices. So what should be the format or type of final file?
0 个评论
回答(1 个)
Erivelton Gualter
2019-5-3
First, there is several ways to import data into Matlab. CHeck the following link:
I recomend to take a look in this answer in order to read the matrix into variables File_i.
https://www.mathworks.com/matlabcentral/answers/161579-how-can-i-import-a-specific-matrix-from-an-excel-file-using-the-xlsread-command
Then, to create the matrix in your desired way, you can check the following code:
clear all
% Matrix
File1 = [1 2 3; 4 5 6; 7 8 9];
File2 = [10 11 12; 13 14 15; 16 17 18];
File3 = [19 20 21; 22 23 24; 25 26 27];
% Size Matrix
[n,m] = size(File1);
N = n*m;
% Reshape
file1 = reshape(File1.', 1, N);
file2 = reshape(File2.', 1, N);
file3 = reshape(File3.', 1, N);
for i=1:N
a = file1(i);
b = file2(i);
c = file3(i);
Out = getM(a,b,c) % Show Output
end
% Function to get Matrix in the desired format.
function out = getM(a,b,c)
out = [a b 0; -b c 0; 0 0 0];
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!