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?
Ältere Kommentare anzeigen
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 Kommentare
Andrew Newell
am 4 Mär. 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
am 9 Mär. 2011
Akzeptierte Antwort
Weitere Antworten (1)
Andrew Newell
am 9 Mär. 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))])
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!