Effacer les filtres
Effacer les filtres

textscan reading via row by row, can it read column by column?

1 vue (au cours des 30 derniers jours)
nori
nori le 13 Mai 2011
hello am trying to use the textscan function to read in ascii files (raster images with each cell containing values between 0-255).
what i have found is that the textscan reads the .asc file row by row into a vector.
now when i try to reshape the vector (so i have the original image again) it does not give the original image (as the reshape function creates each column first, instead of each row first).
i also tried to transpose the reshape but it didnt work out how i was expecting.
for ex.
original file.
1 2 3
4 5 6
textscan vector
1
2
3
4
5
6
reshaped textscan vector
1 3 5
2 4 6
i could use the load function but i have a 6 line header that i need to skip and the textscan function works great for that.
any suggestions would be greatly welcomed.
thanks. nori

Réponse acceptée

Titus Edelhofer
Titus Edelhofer le 13 Mai 2011
Hi,
if you happen to get
1 2 3
4 5 6
already into
x=[1
2
3
4
5
6]
Then you are nearly done:
X = reshape(x, 3, 2)'
or more general if you know the number of rows:
X = reshape(x, length(x)/nRows, nRows)';
Titus

Plus de réponses (1)

nori
nori le 15 Mai 2011
thanks! i came to the same conclusion shortly after posting. funny how sometimes you focus on 1 thing and are blind to the obvious solution.
cheers.

Catégories

En savoir plus sur Large Files and Big Data dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by