简体   繁体   English

Matlab优化矩阵乘法

[英]Matlab Optimize Matrix Multiply

This is my current matlab code: 这是我目前的matlab代码:

a = load('m1.txt');
b = load('m2.txt');
c = a*b;
fid = fopen('Matrix.txt','wt');
for ii = 1:size(c,1)
fprintf(fid,'%g\t',c(ii,:));
fprintf(fid,'\n');
end
fclose(fid)

Basically read in two files and multiply the result to get the multiplied matrix, and write it to a file. 基本上读入两个文件并将结果乘以得到乘法矩阵,然后将其写入文件。

I'm suppose to find out if there is a cache friendly way to do this. 我想要找出是否有缓存友好的方法来做到这一点。 But I think matrix somewhat efficient in this area opposed to other programming languages sometimes. 但是我觉得这个领域的矩阵在某种程度上与其他编程语言相反。 Any hints or sample code? 任何提示或示例代码?

Matlab matrix multiplication is really very efficient. Matlab矩阵乘法非常有效。 I do not think that you can do better than what is already there. 我认为你不能比现有的更好。

You can use the save command to simplify the write to disk loop. 您可以使用save命令简化写入磁盘循环。

save Matrix.txt c -ascii

This will write to disk the variable 'c' in ascii format. 这将以ascii格式将变量'c'写入磁盘。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM