简体   繁体   中英

Matlab Optimize Matrix Multiply

This is my current matlab code:

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. 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 Matrix.txt c -ascii

This will write to disk the variable 'c' in ascii format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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