How to fill in a zeroes matrix using data from a separate array?

Technical Source
2 min readFeb 12, 2024

--

I am trying to work out how to fill in a matrix of zeroes to represent precedence requirements.

I have a 40x40 matrix of zeroes, and each collumn and row represent the tasks 1:40. I also have a 121x2 matrix with the precedent requirements. This is such that if a task needs to be completed before a different task can start, the first task is listed in collumn one and the second in collumn two.

I want to represent this in the form of having a matrix of 1s and 0s where a 1 is placed in row 1 collumn 2, it shows that task 2 relys on task one having happened. If there is a 0 there is no precedence requirement.

Is there a way i can take my 121x2 matrix and populate the 40x40 matrix accordingly? I assume it will be through a loop of reading each like of the 121x2 matrix and populating the 40x40 in this way but i wouldn’t know how to approach the code for this.

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

Sounds like a job for accumarray, e.g,

requirements=[1 2; 2 3; 3 4; 4 6; 5 8]
requirements = 5×2
1 2
2 3
3 4
4 6
5 8
matrix = accumarray(requirements,1,[40,40])

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet