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 件のコメント
KSSV
2022 年 3 月 16 日
Convert where? You want to write it into a text file?
Mohamed Ahmed
2022 年 3 月 16 日
yes using fprintf
採用された回答
KSSV
2022 年 3 月 16 日
x = 1:8 ;
f = [repmat('%d,',1,length(x)-1),'%d\n'] ;
fprintf(f,x)
1,2,3,4,5,6,7,8
15 件のコメント
Mohamed Ahmed
2022 年 3 月 16 日
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);
KSSV
2022 年 3 月 16 日
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
Walter Roberson
2022 年 3 月 16 日
XC = 1:length(X);
f = [repmat('%d,',1,length(XC)-1),'%d'] ;
fprintf(fid, ['frequency points = "', f, '"\n'], XC);
Mohamed Ahmed
2022 年 3 月 16 日
編集済み: Mohamed Ahmed
2022 年 3 月 16 日
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);
KSSV
2022 年 3 月 16 日
It will display the numbers (integers) in X.
Mohamed Ahmed
2022 年 3 月 16 日
Ok, but how can I make it display the numbers as they are not only integers ?
KSSV
2022 年 3 月 16 日
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
Walter Roberson
2022 年 3 月 16 日
f = [repmat('%.4f,',1,length(X)-1),'%d'] ;
fprintf(fid, ['frequency points = "', f, '"\n'], X);
Walter Roberson
2022 年 3 月 16 日
Also consider mat2str()
Mohamed Ahmed
2022 年 3 月 16 日
It still providing the same output (values from 1 to 8)
KSSV
2022 年 3 月 16 日
That means you have not changed x. Show us you full code.
Mohamed Ahmed
2022 年 3 月 16 日
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);
KSSV
2022 年 3 月 16 日
x = logspace(log10(1),log10(10),10);
f = [repmat('%.4f,',1,length(x)-1),'%.4f'] ;
fprintf(fid,['frequency points = "', f,'";'],x);
Mohamed Ahmed
2022 年 3 月 16 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
