Matrix to numbers in script?
11 ビュー (過去 30 日間)
古いコメントを表示
Hi i dont know if this is possible but, if i have a matrix (1x50 double) named "numbers" that generates from one .m file once all iterations are complete, is it possible to get it written out in a vector called "bestNumbers" in another m.file?
Right now i have:
BestNumbers = [numbers];
But i would like for it to be (in the script not command window):
BestNumbers = [ 1 3 4 5 17 and so on ]
Thankfull for any tips,
/ Jasmine
3 件のコメント
Stephen23
2023 年 10 月 4 日
編集済み: Stephen23
2023 年 10 月 4 日
"is it possible to get it written out in a vector called "bestNumbers" in another m.file?"
That would not be a very easy or efficient approach.
Most likely you should simply pass the data as a function output as Dyuman Joshi recommended, or store it as DGM stated.
回答 (1 件)
DGM
2023 年 10 月 4 日
編集済み: DGM
2023 年 10 月 4 日
If you're just generating a set of constants to embed into the script, you can use mat2str(), though depending on your actual values and the amount of space you're willing to use, you may have to compromise on precision. For integers, that shouldn't matter.
result_of_calibration = randi(99,1,20);
mat2str(result_of_calibration) % dump to console
% ... then you can copy and paste that into your script like so
calconstants = [37 66 56 5 1 5 50 35 62 95 32 2 55 19 99 7 36 28 68 82];
For non-integer floats, you'll want to select an appropriate output precision.
For larger arrays, especially floats at higher precision, you may be better off just including them in an accompanying .mat file instead of embedding the array in the script as a giant constant.
@Dyuman Joshi also has a good point to consider.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!