How to change value for linear increasing column-structure

조회 수: 3 (최근 30일)
André
André 2016년 1월 25일
댓글: Guillaume 2016년 1월 26일
My question is about changing values in a matrix linearly. I have a 594x1183 matrix and each cell has a value of 10. I want to change certain parts in a matrix to other values. In the solid-lined box I have a matrix with values of 10. In the dash-lined box I want to have a value of -16.
As you can see, from column 1019 to end (1183) the value should be -16. This also holds for column 1020 (to end) ... to column 1054 (to end) for the rows 54 to 182.
I can do it either manually with Excel (time-consuming) or make for every row a loop (128 loops, also time-consuming). I think there must be a quicker way to solve this problem.
Anyone idea?
Thanks in advance!
Image can be found here as well: http://i.stack.imgur.com/s9DXy.png
Cheers
  댓글 수: 2
Stephen23
Stephen23 2016년 1월 25일
Your data did not get attached. To upload data you need to click the paperclip button, and then both the Choose file and Attach file buttons.
André
André 2016년 1월 25일
My apologies. I hope this is much clearer now! Thanks in advance.

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

채택된 답변

Guillaume
Guillaume 2016년 1월 25일
편집: Guillaume 2016년 1월 25일
There are many ways of achieving this. Here is one:
m = zeros(594, 1183) + 10;
m(logical([zeros(53, 1183);
zeros(129, 1018), triu(ones(129, 165));
zeros(412, 1183)])) = -16;
  댓글 수: 2
André
André 2016년 1월 25일
Thank you for your prompt response, Guillaume. However, the 'triangle' is mirrored (see attachment). The triangle has the following coordinates: (row 182, column 1019), (row 54, column 1019) and (row 54, column 1054).
Also, could you maybe elaborate a bit more what you did?
Thanks!
Guillaume
Guillaume 2016년 1월 26일
I'm unclear whether you're saying that my code generates the pattern you showed (it does not) or you're saying that's the pattern you want (which does not correspond to your earlier question).
What I did is very simple, just stick together square matrices of logical 0 and 1, and for the triangular part simply use http://www.mathworks.com/help/matlab/ref/triu.html|triu| to only keep the upper triangle of a matrix of one.
The combination of logical matrices is then used as a mask to select elements to be assigned. This is basic logical indexing

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by