How to put these values into one array ?
显示 更早的评论
I have this vector X which is equal to
X =
Columns 1 through 8
1 2 3 4 5 6 7 8
I want to convert it into this format
X =
1, 2, 3, 4, 5, 6, 7, 8
How can I achieve this ?
2 个评论
Convert where? You want to write it into a text file?
yes using fprintf
采纳的回答
x = 1:8 ;
f = [repmat('%d,',1,length(x)-1),'%d\n'] ;
fprintf(f,x)
1,2,3,4,5,6,7,8
15 个评论
How can I apply it into this code below ?
X = 1:length(X);
f = [repmat('%d,',1,length(X)-1),'%d\n'] ;
fprintf(fid,'frequency points = "f"',X);
x = 1:8 ;
f = [repmat('%d,',1,length(x)-1),'%d\n'] ;
fprintf(['frequency points = ',f],x)
frequency points = 1,2,3,4,5,6,7,8
XC = 1:length(X);
f = [repmat('%d,',1,length(XC)-1),'%d'] ;
fprintf(fid, ['frequency points = "', f, '"\n'], XC);
Does this funtion display the numbers in X or it just the values from 1 to 8 ?
X = 1:length(X);
f = [repmat('%d,',1,length(X)-1),'%d\n'] ;
fprintf(fid,['frequency points = "',f,'";'],X);
It will display the numbers (integers) in X.
Ok, but how can I make it display the numbers as they are not only integers ?
Repalce %d with %f.
Mohamed Ahmed
2022-3-16
编辑:Mohamed Ahmed
2022-3-16
when I tried it the output was just the numbers from 1 to 8, and it doesn't if I change X values.
These are the X values I want:
1.0000 1.0608 1.1253 1.1938 1.2664 1.3434 1.4251 1.5118 1.6037 1.7013
f = [repmat('%.4f,',1,length(X)-1),'%d'] ;
fprintf(fid, ['frequency points = "', f, '"\n'], X);
Also consider mat2str()
It still providing the same output (values from 1 to 8)
That means you have not changed x. Show us you full code.
x = logspace(log10(1),log10(10),10);
x = 1:length(x);
f = [repmat('%.4f,',1,length(x)-1),'%.4f'] ;
fprintf(fid,['frequency points = "', f,'";'],x);
x = logspace(log10(1),log10(10),10);
f = [repmat('%.4f,',1,length(x)-1),'%.4f'] ;
fprintf(fid,['frequency points = "', f,'";'],x);
yess, this one worked.
Thank you!!!
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
