我想写一段代码,它可以把一组数据集合起来,然后打印到小数点后的3位。我知道我需要使用Ceil函数,但不知道如何编写正确的代码。我的代码只打印1和2!例如,1.2345圈到2.000圈。我想用ceil函数把这个数字除以为1.235。
我的代码是:
row = 1;
col = 1;
HIGH_ERROR = 2.5;
LOW_ERROR = 0.0;
% Read the file
rawData = dlmread('data_1.csv',',');
% Get the size
[MAX_ROWS, MAX_COLS] = size(rawData);
errorMap = double(zeros(MAX_ROWS, MAX_COLS));
value = ceil(rawData(row, col)*1000/1000);
%Print the raw data
fprintf('Raw Data\n');
for row = 1 : MAX_ROWS
for col = 1 : MAX_COLS
fprintf('%0.3f ', rawData(row, col));
end
fprintf('\n');
end
%Print the Error Map
fprintf('Error Map\n');
for row = 1 : MAX_ROWS
for col = 1 : MAX_COLS
if rawData(row, col) > HIGH_ERROR
errorMap(row, col) = rawData(row, col);
rawData(row, col) = HIGH_ERROR;
if rawData(row, col) < LOW_ERROR
errorMap(row, col) = rawData(row, col);
rawData(row, col) = LOW_ERROR;
end
end
fprintf('%0.3f ', errorMap(row, col));
end
fprintf('\n');
end
%Print the Rounded Data
fprintf('Rounded Data\n');
for row = 1 : MAX_ROWS
for col = 1 : MAX_COLS
value = ceil(rawData(row, col)*1000/1000);
fprintf('%0.3f ', value);
end
fprintf('\n');
end发布于 2017-10-01 01:15:45
我想你想
value = ceil(rawData(row, col)*1000)/1000;发布于 2017-10-01 01:24:49
对于任何有round()的语言来说,一个很好的技巧应该是:
-> ceil(x) = round(x + 0.5).
(地板) -> floor(x) = round(x - 0.5)。
https://stackoverflow.com/questions/46508265
复制相似问题