How to change value for linear increasing column-structure

4 次查看(过去 30 天)
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 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by