Info

This question is closed. Reopen it to edit or answer.

When matlab coordinate is disagreed with file coordinate generated from external software

1 view (last 30 days)
I use Matlab to visualize the data in 3D. The data is generated by external software. I think I followed well the syntex upon slice function for 3D graphics. However, when slice function applies, the results is not right to the read file. I mean that Matlab coordinate shows x, y, z in clockwise. But when Matlab read the file, the 3D graphic data showed y,x,z in clockwise. Have you ever had similiar experience with me? Or Am I doing something wrong? I check my code many times but I can not see anything wrong. If you know a solution for this case, would you let me know please?

Answers (1)

Walter Roberson
Walter Roberson on 8 Mar 2011
How are you doing the reading?
Remember that Matlab arrays are stored down columns not across rows, so if you fill sequential memory locations with values that you read from rows, you are going to be writing down columns.
For example, for a 3 x 2 array, A(1,1) is in memory next to A(2,1) which is next to A(3,1) which is next to A(1,2) which is next to A(2,2) which is next to A(3,2).
1 4 2 5 3 6
which would correspond to reading in the file
1 2 3 4 5 6
  4 Comments
Soyoung
Soyoung on 9 Mar 2011
Here is file-read-method.
%%%
filename = sprintf('originalfile.kkk');
fid = fopen(filename,'r');
temp_data=fgets(fid);
data = sscanf(temp_data, '%f');
%%%
in this way, I read the file. Since my file is ASCII file, I used fgets to read file because fscanf took long and textread did work. I assumed you would guess this reading part. Is it something bad to read the file? How do you think?
Walter Roberson
Walter Roberson on 9 Mar 2011
That form of reading is going to result in a vector of values, not a 3 dimension array such as would be needed to extract data in the loop you showed.
If you used reshape() on the data to get a 3 dimensional array, then you are going to have exactly the difficulty I noted above: that consecutive values Matlab reads in will be stored down columns.
To fix this issue, use
data = permute(file, [2 1 3]);

This question is closed.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!