cndkrt
cndkrt

Reputation: 79

How to define matrix values as a index in matlab?

I have 1788x3 double matrix. My goal is split first and seconds columns values as a coordinates and create 256*256 matrix. Missing values will be zero.

That is the part of my matrix: For example in 256*256 matrix (161,37) coordinates value will be 0.347365914411139

161 37  0.347365914411139
162 38  0.414350944291199
160 38  -0.904597803215328
165 35  -0.853613950415835
163 38  -0.926329070526244
166 35  -1.37361928823183
168 37  0.661707825299905

Looking forward your answers. Regards;

Upvotes: 0

Views: 38

Answers (1)

learnvst
learnvst

Reputation: 16193

The easiest, but not necessarily most efficient way to do this would be using a loop, i.e.

% if m = you 1788x3 data

x = sparse(256,256) %// x = zeros(256); % //use either of these 
for nn = 1:size(m,1)
    x(m(nn,1),m(nn,2)) = m(nn,3);
end

Upvotes: 1

Related Questions