Adding a variable to a square zeros matrix given x and y coordinates calculated from separate vectors

Ive got two vectors made of 0s and one possible 1, ive calculated the positions of the said 1 as
classpos=find(classlabels==1); %X Coordinate position retating to class labels
truepos=find(truelabels==1); %Y Coordinate position relating to true labels
M=zeros(10,10); %10x10 Zeros matrix creation
how do I place a 1 in the positions i've calculated and do this cumulatively as this will appear in a for loop for repetitively adding 1s to this square matrix given their coordinates in two independent vectors. Thank you for your time, Jacob

2 件のコメント

What is M and how is it related to your "coordinates"? Are you setting an M element to 1, or cumulatively adding 1 to appropriate M elements? Can you show us your for-loop code?
I havent made a for loop yet for the data I want to set an element according to (x,y) co-ords to 1 and then as the loop moves on it should incrementally add 1 to the position specified, if that makes sense. Thank you.

サインインしてコメントする。

 採用された回答

It is unclear what the M matrix is supposed to be, but is this what you need?
M(classpos,truepos) = 1;

2 件のコメント

Damn I didn't think the solution would be that simple, thank you mate.
Sorry do you know how I can add 1 to each position defined by classpos and truepos inside of a for loop?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by