这是我的MATLAB代码:
mu_n = Tnume_mu/Tdeno_mu;
当我运行它时,它始终显示0,尽管变量Tnume_mu = 255
和Tdeno_mu = 1.7957e4
。
答案 0 :(得分:6)
你检查了变量的类吗?
>> x = int32(5);
>> y = int32(10);
>> class(x)
int32
>> class(y)
int32
>> x / y
0
但
>> x = 5;
>> y = 10;
>> class(x)
double
>> class(y)
double
>> x / y
0.5
整数变量(int8
,int16
,int32
,int64
)只能取整数值,并且在除法期间舍入为零,因此如果结果将介于0和1之间,然后结果为0。
答案 1 :(得分:0)
为了简化问题,我将使用更简单的变量名称和数字:
/
A = magic(2);
B = magic(2).';
C = A./B;
C =
1.0000 0.7500
1.3333 1.0000
运算符是Using annotations的捷径。这是两个标量之间的常规划分。您可以将其扩展为矩阵,例如
./
\
确保您明确划分元素。
还有另一个部门,即左 -divide:rdivide
,或简称C = A^-1 * B
。这是一个特定的MATLAB运算符,矩阵乘法通常用A^-1
表示,其中A
是矩阵C=A\B
C =
0.7000 -0.2000
0.1000 1.4000
D = inv(A)*B;
C == D
1
的反函数。这个算子的优点在于它不会明确计算逆,而是对它进行******分解,使其更快,更强大。这不是问题,因为您很少需要矩阵的显式逆,您可以通过ldivide
创建矩阵:
static class FirmwareDownload extends AsyncTask<String, String, String> {
public String TAG = "Super LOG";
public String file;
int lenghtOfFile;
long total;
@Override
protected String doInBackground(String... f_url) {
try {
int count;
Utilies.getInternet();
URL url = new URL(f_url[0]);
URLConnection connection = url.openConnection();
connection.connect();
lenghtOfFile = connection.getContentLength();
mProgressBar.setMax(lenghtOfFile);
InputStream input = new BufferedInputStream(url.openStream(), 8192);
String fileName = f_url[0].substring(f_url[0].lastIndexOf("/"), f_url[0].length());
File root = Environment.getExternalStorageDirectory();
File dir = new File(root.getAbsolutePath() + fileName);
Log.d(TAG, "trying to download in : " + dir);
dir.getAbsolutePath();
OutputStream output = new FileOutputStream(dir);
byte data[] = new byte[1024];
while ((count = input.read(data)) != -1) {
if (isCancelled())
break;
total += count;
mProgressBar.setProgress(Integer.parseInt("" + total));
Log.d("Downloading " + fileName + " : ", " " + (int) ((total * 100) / lenghtOfFile));
mPercentage.post(new Runnable() {
@Override
public void run() {
mPercentage.setText(total / (1024 * 1024) + " Mb / " + lenghtOfFile / (1024 * 1024) + " Mb");
}
});
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
//new InstallHelper().commandLine("mkdir data/data/ota");
File fDest = new File("/data/data/ota/" + fileName);
copyFile(dir, fDest);
FirmwareInstaller fw = new FirmwareInstaller();
fw.updateFirmware();
} catch (Exception a) {
System.out.println("Error trying donwloading firmware " + a);
new InstallHelper().commandLine("rm -r data/data/ota");
dialog.dismiss();
}
return null;
}
}