Matrix to numbers in script?

조회 수: 7 (최근 30일)
Jasmine Larsson
Jasmine Larsson 2023년 10월 4일
댓글: Jasmine Larsson 2023년 10월 9일
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
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.
Jasmine Larsson
Jasmine Larsson 2023년 10월 9일
Thank you all for the answers, i understand it is not super efficient but it was just for an assignment. I was hoping there was a more efficient or clever ;) way to do this but i will just use copy and paste as @DGM said, which was the original plan. Thanks!!!

댓글을 달려면 로그인하십시오.

답변 (1개)

DGM
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
ans = '[37 66 56 5 1 5 50 35 62 95 32 2 55 19 99 7 36 28 68 82]'
% ... 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.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by