Replace part of a column in a matrix with different values
2 views (last 30 days)
Show older comments
Hi all,
I have a matrix C, its size is dependent on some non-dimensional variables I have previously defined. Initially, C has a constant value (=1) in column one, and zeros else. However, I need to redefine part of the first column in C. More specifically, I need to define the last 3/4 rows of C (represented by a dimensionless variable [LLY] ). However, when doing so I yield a non-integer value:
length_x= LLX/dx <== dx,LLX dimensionless
length_y= LLY/dy; <== dy,LLY dimensionless
C=zeros(length_y,length_x);
A=.25*LLY
C(A:LLY,1)=1;
~~~~
EDU>> LLY
LLY =
1
~~~
Where LLY represents a dimensionless length. With units, LLY has the length of 2000, I would like to redefine the values in column one for rows 500 through 2000 with a value of 1. However, because of the nature of non-dimensional variables LLY is defined to be 1.
I cannot pre-define C with dimensions (units) because the resulting matrix will be too large for Matlab, thus why I need to make it dimensionless. Any ideas how to overcome the resulting non-integer value of 0.25?
~~~~~
EDU>> A
A =
0.2500
~~~~~
Thank you in advance, Kevin
0 Comments
Accepted Answer
Cedric
on 14 Apr 2013
Edited: Cedric
on 14 Apr 2013
This is a valid approach only when LLY is a multiple of 4. I am unsure what it is that you want to achieve, but if you want to guarantee that A is an integer such as 1 <= A <= LLY with LLY >= 1, you can define A as:
A = max(1, round(LLY/4)) ;
0 Comments
More Answers (1)
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!