fprintf('%-5s %d',counts(i));输出为乱码
时间: 2023-12-27 22:03:18 浏览: 46
`fprintf` 函数的第一个参数是格式化字符串,其中 `%s` 表示输出一个字符串,`%d` 表示输出一个整数。在你的代码中,你只给了一个 `%s` ,但是并没有给出第二个参数,也就是要输出的字符串。因此,如果你想要将 `counts(i)` 输出为字符串,可以使用 `num2str` 函数,将其转换为字符串后再输出。下面是修改后的代码:
```matlab
fprintf('%-5s %d', num2str(counts(i)), i);
```
这样就可以将 `counts(i)` 输出为字符串,再和整数 `i` 一起输出了。如果你还是发现输出的结果是乱码,可能是因为你的输出格式与当前字符集不兼容,可以尝试更改字符集或使用其他输出方式,如 `disp` 函数。
相关问题
fprintf中的%-15s
As an AI language model, I am programmed to understand the concept of "null" as a value that represents the absence of a meaningful or valid data value. In programming languages, "null" is often used to indicate the absence of an object, variable or value. It is also commonly used to indicate an empty or undefined state.
将下面C语言风格的句子转变成C++风格的句子 fprintf(fp,"%s ", in[i].F_Name); fprintf(fp," %-8d ", in[i].F_num); fprintf(fp," %-8f ", in[i].price); fprintf(fp," %-8s ", in[i].description); fprintf(fp," %-8s ", in[i].F_Spec); fprintf(fp," \n\n ");
fp << in[i].F_Name << " " << setw(8) << in[i].F_num << " " << setw(8) << in[i].price << " " << setw(8) << in[i].description << " " << setw(8) << in[i].F_Spec << " \n\n ";
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)