Problem when using set.property method on a property of matrix type ? How to access the value of only one element of the matrix within the set.property method?
Show older comments
Hi everyone,
This is a general question on using the set.property method when the property is a matrix (contains several elements and thus several values)
Problem: I have a Class "Test" with a property "Matrix". This property is a nx1 matrix. During code execution I create an instance of this class and the code modifies each row of this property "Matrix" one after the other. I would be interested in adding a listener in order to detect when one of the Matrix element exceeds a given value. However, when setting-up the set.Matrix method I cannot access a particular row as my "Row_ID" indicator is not defined within the class. I can only access the property "Matrix" entirely but looses information on the current Row_ID.
Do I have to include the "Row_ID" as one of the class property to be able to access ii within set.Matrix ? Even if using other properties within a set property method is not recommended (Matlab help) ?
Any suggestion on a way to integrate this listener would be much appreciated...
Ben
2 Comments
Andrew Newell
on 4 Mar 2011
What you seem to be saying is that, as you modify the matrix (really a vector) element by element, you want the listener to know when *any* element exceeds a certain value. Is that right? Do you need to know which element exceeds the value, or will it do to look at MAX(ABS(MATRIX))?
Benjamin Guinot
on 9 Mar 2011
Accepted Answer
More Answers (1)
Andrew Newell
on 9 Mar 2011
And here is a simple for loop that does everything you want:
x = zeros(100,1);
maxValue = 10;
for i=1:length(x)
x(i) = input('Next number: ');
if x(i) > maxValue
break
end
end
disp(['Maximum exceeded at index number ',num2str(i)])
disp(['Value at this point = ',num2str(x(i))])
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!