Updating a zeroized matrix with provided row vectors

So I'm not sure if this can be done, but this is what I'm trying to do. I have a matrix (Force) that I've initialized to zero, it will always have three columns, but the rows will vary based on the nnd variable (determined by user input). Also based on user input is the Nodal Loads matrix, where Column 1 is the node number and column 2:4 are nodal loads. As you can see, there are nodes missing in the user input, meaning that if the user didn't input a value, then that nodal row remains zero. Is there a way to take the user input for Nodal_Loads and update the information into the Force matrix? My desired endstate is shown below. Thanks for the help.
Nodal_Loads = [2 0 -1000 0] %example 1
or
Nodal_Loads = [1 0 0 40; 3 -1000 0 40; 4 0 2000 40; 5 0 0 40; 8 1000 -2000 40; 9 0 0 40] %example 2
nnd = 9 %can be any number based on user input (I'll just say 9 for this example)
Force = zeros(nnd,3)
(Desired Endstate) %example 2
Force matrix now looks like:
Force = [0 0 40; 0 0 0; -1000 0 40; 0 2000 40; 0 0 40; 0 0 0; 0 0 0; 1000 -2000 40; 0 0 40]

 Accepted Answer

Force(Nodal_Loads(:,1),:) = Nodal_Loads(:,2:4)

1 Comment

That's perfect and very simple. Thanks, I'll make sure to take note of this for future use.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2019b

Asked:

on 10 Mar 2020

Commented:

on 10 Mar 2020

Community Treasure Hunt

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

Start Hunting!