Simplify Matrix decimal to integers
Ältere Kommentare anzeigen
I do not want
881/2158 985/1393 780/1351
881/2158 -985/1393 780/1351
-881/1079 0 780/1351
But I want
1 1 1
1 -1 1
-2 0 1
How do I do this using one single function ?
I get this error if I use simplify
Check for incorrect argument data type or missing argument in call to function 'simplify'.
Antworten (2)
Alan Stevens
am 19 Okt. 2021
Bearbeitet: Alan Stevens
am 19 Okt. 2021
One way is
M = [881/2158 985/1393 780/1351
881/2158 -985/1393 780/1351
-881/1079 0 780/1351]
ip = find(M>=0);
in = find(M<0);
M(ip) = ceil(M(ip));
M(in) = floor(M(in));
disp(M)
Don't know where you got the -2 from though!
1 Kommentar
Shaunak Bagade
am 19 Okt. 2021
Cris LaPierre
am 19 Okt. 2021
Bearbeitet: Cris LaPierre
am 19 Okt. 2021
It's likely going to take two functions: one to convert your symbolic expressions to numeric, and a second to round.
I would probably do something like
new_var = round(double(old_var))
5 Kommentare
Shaunak Bagade
am 19 Okt. 2021
Cris LaPierre
am 19 Okt. 2021
You say you are getting an error message, so you must have code already. Please share what you have tried.
M = [881/2158 985/1393 780/1351
881/2158 -985/1393 780/1351
-881/1079 0 780/1351];
B = M./M(1,:)
Or you could normalize by the first element in each column.
M = [881/2158 985/1393 780/1351
881/2158 -985/1393 780/1351
-881/1079 0 780/1351];
B = normalize(M, 1, 'scale', 'first') % Normalize in dimension 1
Shaunak Bagade
am 19 Okt. 2021
Bearbeitet: Shaunak Bagade
am 22 Okt. 2021
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!