convert an array value into corresponding Matrix indices
Show older comments
Given an array of values, I would like to place a "1" into the corresponding Matrix element

I'm currently doing...
matrix = zeros( numDatapoints,10 ); %Start with a zero matrix of correct size
for row = 1:numDatapoints
for i = 1:10
if dataArray(row,17) == i %compare the value of the array to the current index
matrix(row,i) = 1;
end
end
Any suggestions to improve this in MATLAB?
1 Comment
Matt J
on 23 Mar 2022
corresponding to what?
Accepted Answer
More Answers (0)
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!