I think this is vectorizing
Mostra commenti meno recenti
Given: Write a code that prompts user to enter a number of rows and columns. Create a matrix, with the provided size that has random integers between -10 and 10.
Find: How do I have MATLAB individually look at each value in the matrix and determine if the value is negative, and if it is, add one to a variable used to keep track of the negative values? (Otherwise do nothing). Then display to the user the number of negative values in the matrix.
Issue: I am running into syntax error brain. In my head this code works, but it's not what MATLAB thinks is right.
My solution: Once I figure out how to get my random numbers to properly generate I can tackle the tracking system... I might be going about this all wrong, though.
R=input('Enter the number of rows: ');
C=input('Enter the number of columns: ');
MAT=[R(randi([-10,10]),C(randi([-10,10])))]; % Getting an error here, syntax?
for x=1:R<1
disp('Negative')
for y=1:C<1
disp('Negative')
end
end
% Then create a variable neg and somehow??? do neg=neg+1 every time there is a
% negative value found in the above for loop.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!