obtain answer in brackets

15 ビュー (過去 30 日間)
DavidL88
DavidL88 2020 年 7 月 2 日
コメント済み: DavidL88 2020 年 7 月 2 日
Hi
I have some data in a 3x1 struct with 2 fields. The data is stored in this fashion [0.1000,0.2500]. When I retrieve the dat using this code Times_period = S_times(1).Times I get ans = 0.1000 0.2500. I want to retieve exactly this [0.1000,0.2500] (ie with square brackets included). Can anyone advsie how I do this?
I tried Times_period = {"[",S_times(1).Times,"]"}. But I get this = 1×3 cell array {["["]} {1×2 double} {["]"]}
Tried other variations but no success.

採用された回答

Fangjun Jiang
Fangjun Jiang 2020 年 7 月 2 日
mat2str(magic(3))
  17 件のコメント
Image Analyst
Image Analyst 2020 年 7 月 2 日
They used brackets in that line of code -- [0.1, 0.25] -- because they needed to create an array (a row vector) from two constants. Like Fangjun said, if you already have this array it wants in your S_times(i).Times, then you can just use that:
'timewindow', S_times(i).Times, ...
There are really no brackets - that's just how you construct an array but they are not actually part of the array itself -- the array is just numbers alone.
DavidL88
DavidL88 2020 年 7 月 2 日
That makes sense. Thank you!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2020 年 7 月 2 日
You can use sprintf() to create a string with any appearance you want.
Or fprintf() to display it with any appearance you want.

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by