How to change value for linear increasing column-structure

3 vues (au cours des 30 derniers jours)
André
André le 25 Jan 2016
Commenté : Guillaume le 26 Jan 2016
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 commentaires
Stephen23
Stephen23 le 25 Jan 2016
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é le 25 Jan 2016
My apologies. I hope this is much clearer now! Thanks in advance.

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 25 Jan 2016
Modifié(e) : Guillaume le 25 Jan 2016
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 commentaires
André
André le 25 Jan 2016
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 le 26 Jan 2016
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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by