Error while evaluating UIControl Callback

function gcopt_Callback(hObject, eventdata, handles)
gen = str2num(get(handles.generator,'String'));
rate = str2num(get(handles.rating,'String'));
outage = str2num(get(handles.outage,'String'));
Data = cell(gen+1, 4);
Data(:,1) = num2cell((0:gen).');
for v = 1:gen+1
Data(v,2) = rate * Data(v,1);
end
f = figure('Position',[440 500 461 146]);
t = uitable(f);
t.ColumnName = {'User Input','Capacity Out','Capacity Available','Probability'};
t.Data = Data;
set(t,'ColumnWidth',{120});
t.Position(3) = t.Extent(3);
t.Position(4) = t.Extent(4);
I'm having this error when I'm trying to multiply the data in the for loop.

1 件のコメント

Jan
Jan 2017 年 10 月 17 日
You forgot to post the error message.

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

 採用された回答

Jan
Jan 2017 年 10 月 17 日
編集済み: Jan 2017 年 10 月 17 日

0 投票

You cannot multiply cells, but only the contents:
for v = 1:gen+1
Data{v,2} = rate * Data{v,1}; % Curly braces
end
Or:
Data(:,2) = num2cell(rate * (0:gen).');

2 件のコメント

Kim Lopez
Kim Lopez 2017 年 10 月 17 日
Thank you so much. I'm new to MATLAB and really appreciate the help.
Jan
Jan 2017 年 10 月 17 日
You are welcome. The handling of cell arrays is not easy at the beginning. Look in the documentation for the examples:
doc cell
docsearch cell

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

タグ

質問済み:

2017 年 10 月 17 日

コメント済み:

Jan
2017 年 10 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by