If the column can be "20 20 20 value", then "20.1 20 20 value","20.2 20 20 value"....... until "40 20 20 value" (after 201 dots), then "20 20.1 20 value", "20 20.1 20 value" .......until "20 35 20 value"(after 151 dots), then "20.1 20.1 20.1 value".... it will be perfect. Thanks again
3D matrix with value of each point convert to .txt file
1 次查看(过去 30 天)
显示 更早的评论
Hi, I have a matrix which is 201*150*100 with value on each point. Right now I'm trying to convert the matrix to .txt. The file is of latitude, longitude, and depth. The ideal format for the .txt file to should be in columns with the shape of lat, long, depth, value. And then the next lane with the same format. If the lat, long, depth can start from 20 with interval increasing 0.1 instead of 0 all the way it will be perfect. Thanks in advance, please let me know if I confused you anywhere.
采纳的回答
Walter Roberson
2017-11-2
[r, c, p] = size(YourMatrix);
[R, C, P] = ndgrid(20 + (0:r-1)*0.1, 20 + (0:c-1)*0.1, 20 + (0:p-1)*.1);
temp = [R(:), C(:), P(:), YourMatrix(:)];
fid = fopen('YourOutputFile.txt', 'wt');
fprintf(fid, '%g %g %g %g\n', temp.' ); %transpose is important
fclose(fid);
更多回答(1 个)
KL
2017-11-2
Why not save each page in separate files? It's much simpler,
for k=1:size(yourMatrix, 3)
A = yourMatrix(:,:,k);
save(sprintf('matrix_page_%d.txt', k), 'A', '-ASCII', '-double');
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!