How to change value for linear increasing column-structure

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 日

0 投票

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 件)

カテゴリ

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

質問済み:

2016 年 1 月 25 日

コメント済み:

2016 年 1 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by