필터 지우기
필터 지우기

Updating a zeroized matrix with provided row vectors

조회 수: 1 (최근 30일)
Damon Schmidt
Damon Schmidt 2020년 3월 10일
댓글: Damon Schmidt 2020년 3월 10일
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]

채택된 답변

BobH
BobH 2020년 3월 10일
Force(Nodal_Loads(:,1),:) = Nodal_Loads(:,2:4)
  댓글 수: 1
Damon Schmidt
Damon Schmidt 2020년 3월 10일
That's perfect and very simple. Thanks, I'll make sure to take note of this for future use.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by