In this code I have a result but I want it as integer numbers.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
n = 12;
m = 6;
numbers = linspace(1, n, m)
index = 1;
theSums = [];
for k = 1 : length(numbers)
for k2 = 1 : length(numbers)
num1(index) = numbers(k);
num2(index) = numbers(k2);
theSums(index) = num1(index) + num2(index);
fprintf('%.4f + %.4f = %.4f\n', num1(index), num2(index), theSums(index));
index = index + 1;
end
end
[uniqueSums, indexes] = unique(theSums)
% Extract only the unique numbers:
num1 = num1(indexes)
num2 = num2(indexes)
% Double check.
for k = 1 : length(indexes)
fprintf('%.4f + %.4f = %.4f\n', num1(k), num2(k), uniqueSums(k));
end
0 Kommentare
Antworten (1)
Image Analyst
am 26 Sep. 2021
round() will turn floating point numbers (doubles) with fractions into floating point numbers (doubles) with no fraction (the fraction is 0).
Or you can use int32() to cast your variable into a 32 bit integer, which of course also does the rounding.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!