How can I read data from 512-by-256-by-128 matrix.

forloop= 1:512
forloop= 1:256
forloop= 1:128
//do something
end
It causes matalab busy.Is there a way to read the data from matrix(i need data in a particular format like data(1,1,1), data(1,2,1), data(1,3,1), data(1,1,2)...and so on . What will i do? Is there any other way ?

Answers (1)

If the data is in matrix form, you can straight away take your required information from data using indexing. You can access data(1,1,1),data(1,2,1),data(1,3,1)....data(1,n,1) at on stretch calling
data(1,:,1)

8 Comments

Actually i have 512x256x128 matrix .i want to read each element from that matrix in format forloop i 1:512 forloop k= 1:128 forloop j= 1:256 read data(i,j,k).
data = rand(512,256,128) ; % make a random data
[m,n,p] = size(data) ;
for i = 1:m
for j = 1:n
for k = 1:p
data(i,j,k)
end
end
end
Whats the necessity to read? When you have data already? Please enlighten me.
I want to write the formatted data from matrix to a file (it have other content) .can't use 'dlmwrite'.
ok...in that case..you can write matrix by matrix into a file and append the 3D matrix.
You can use fprintf to write whole matrix...
If you have a matrix you want to write out in a different order, you can almost always do it by using fprintf() or fwrite() in combination with permute(), without needing for loops.

Sign in to comment.

Asked:

on 19 Oct 2016

Commented:

on 25 Oct 2016

Community Treasure Hunt

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

Start Hunting!