[討論] 如何將structure內各field轉存為variables?
各位前輩大家好
我成功讓函數輸出structure了
現在希望讓structure中每個field
依照其field名稱生成variables
而內容則為原先variables的內容
如
set =
electronicdelay: 1.0900
timeinterval: 0.0250
res: 0.7000
wavenumber: [7259x1 double]
Nwavenumber: 7259
Ntime: 4000
time: [1x4000 double]
希望生成
1.electronicdelay
2.timinterval
...
等變數
網路上搜尋到了一個函式structvars
可以產生下列文字
(a為char)
>> a=structvars(set)
a =
electronicdelay = set.electronicdelay;
timeinterval = set.timeinterval;
res = set.res;
wavenumber = set.wavenumber;
Nwavenumber = set.Nwavenumber;
Ntime = set.Ntime;
time = set.time;
基本上我只要複製a的內容
然後丟到CMW內輸出即可
然而我希望可靠程式碼達到這動作
因此試著使用eval
但會出現下列結果
>> eval(a)
Error: The expression to the left of the equals sign is not a valid target
for an assignment.
我確定a屬於char
我嘗試手動將a中文字的頭跟尾加上單引號
結果是可行的
我最終的目標如同標題
但我能想到的方法如同我前面敘述
卡在最後一步將a的內容執行
是否可以給我一點建議?
: 各位前輩大家好
: 我最近使用matlab處理實驗數據
: 寫了一個function A
: 並將經A運算處理後
: 之有用數據存為一結構
: 如下
:
: trace =
:
: 1x2 struct array with fields:
:
: Jmax
: PInf
: RInf
: P
: R
: Pindex
: Rindex
:
: 希望此function可以輸出trace這個結構寫為
: function [trace] = function(input)
: 然而function似乎只可以輸出變數
: 請問有方法可讓我從A中輸出trace這個結構嗎?
:
: 謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.224.210
※ 文章網址: https://www.ptt.cc/bbs/MATLAB/M.1446828993.A.B44.html
推
11/07 00:59, , 1F
11/07 00:59, 1F
推
11/07 09:24, , 2F
11/07 09:24, 2F
→
11/07 13:28, , 3F
11/07 13:28, 3F
→
11/07 13:29, , 4F
11/07 13:29, 4F
→
11/07 13:32, , 5F
11/07 13:32, 5F
→
11/07 13:32, , 6F
11/07 13:32, 6F
→
11/07 13:33, , 7F
11/07 13:33, 7F
→
11/07 13:34, , 8F
11/07 13:34, 8F
※ 編輯: kusoer1017 (140.113.224.210), 11/07/2015 23:51:37
※ 編輯: kusoer1017 (140.113.224.210), 11/07/2015 23:52:24
→
11/08 00:57, , 9F
11/08 00:57, 9F
Q_Q 總之我想把一個結構變數內的各個field獨立出來
例如我本來要呼叫set.wavenumber
我希望把wavenumber從set內取出
產生一個新的變數名稱就叫做wavenumber
內容跟set.wavenumber一樣
※ 編輯: kusoer1017 (140.113.224.210), 11/08/2015 12:51:04
→
11/08 13:02, , 10F
11/08 13:02, 10F
→
11/08 13:03, , 11F
11/08 13:03, 11F
→
11/08 13:03, , 12F
11/08 13:03, 12F
→
11/08 13:04, , 13F
11/08 13:04, 13F
→
11/08 13:09, , 14F
11/08 13:09, 14F
再次確認了一下
a是個7*43的char
我也很困惑為啥不能直接eval
會出現
Error: The expression to the left of the equals sign is not a valid target
for an assignment.
※ 編輯: kusoer1017 (140.113.224.210), 11/08/2015 14:03:48
→
11/08 14:07, , 15F
11/08 14:07, 15F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章