Unable to call table2array in another function

조회 수: 3 (최근 30일)
Hanisah Rashid
Hanisah Rashid 2020년 11월 28일
댓글: Walter Roberson 2020년 11월 29일
Hi,
I have a table with only 1 column containing numeric data.
filename = 'dataset_Facebook_modified.csv';
data = readtable(filename);
labels = data(:,end);
Then I want to create a function called 'l_std' where I'm trying to use table2array to carry out some calculations.
function [labels_std, labels_avg] = l_std(labels)
labels_std = 0;
labels_avg = 0;
label = table2array(labels);
labels_std = std(label)
labels_avg = mean(label)
end
However, I got the error message as below (red text):
Brace indexing is not supported for variables of this type.
Error in table2array (line 27)
a = t{:,:};
Error in l_std (line 5)
label = table2array(labels);
When I run it in the main tab, it works fine. I just cannot run it in another function (in another tab).
Can anyone advise where is the error and how to solve it?

채택된 답변

M.Many
M.Many 2020년 11월 28일
편집: M.Many 2020년 11월 28일
labels = data{:,end};
Use this to directly get labels as an array instead of a table. There is no need to use table2array.
  댓글 수: 10
Hanisah Rashid
Hanisah Rashid 2020년 11월 29일
I understand that I can set the initial variables directy to arrays and change back to table when I needed it, but I'm just stumped figuring out where I got it wrong.
Walter Roberson
Walter Roberson 2020년 11월 29일
We do not know, as we have not seen the code for that other "tab".
I am not even clear what a "tab" is for this purpose?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by