I cann't insert calculated variable (make it to properties var)into ther row with colum name "Result"

1 vue (au cours des 30 derniers jours)
It error to insert calculated variable (make it to properties var)into ther row with colum name "Result" but the error pop-up is "Error using .
Unable to perform assignment because the left and right sides have a different number of elements." for this code
app.up = readtable("List_of_Result_Uplink.xlsx","Sheet",1);
app.uplinkresultTable.Data = app.up;
app.up.Properties.VariableNames{1} = 'List';
app.up.Properties.VariableNames{2} = 'Parameter';
app.up.Properties.VariableNames{3} = 'Result';
app.up.Properties.VariableNames{4} = 'Unit';
app.uplinkresultTable.ColumnName = app.up.Properties.VariableNames;
app.up.Result(1) = app.ptu1;
app.up.Result(2) = app.path;
app.up.Result(3) = app.snr_tu;
app.up.Result(4) = app.Ru;
app.up.Result(5) = app.Bwu;
app.up.Result(6) = app.T_su;
app.up.Result(7) = app.l_pu1;
my table name "up" (app.up with properties) . I will insert in colum name with different row about calculated variable

Réponses (1)

Walter Roberson
Walter Roberson le 4 Août 2022
app.up.Result(1) = app.ptu1;
app.up.Result(2) = app.path;
For those assignments to work, each of the values being assigned would have to be the same size, and would have to be convertible to the data type that readtable used for the third variable in the table. For example it could work if the column was created as numeric and all the values being stored were scalar numeric. If the column was created as a cell array of character vectors then the assignments could work if the right hand sides were each a scalar cell array.
My guess though is that the column is numeric, but app.path is a character vector. The immediate problem causing the error would not be the difference between character and numeric, as char automatically converts to the internal character codes such as 65 encoding 'A'. The problem would be that character vectors are not scalar items, they are char array, and 2 or more characters would not fit into the scalar location Results(2)
If you want to store different sizes or data types you need to ensure that the column is a cell array and that you use cell storage operations such as {} indexing

Catégories

En savoir plus sur Scope Variables and Generate Names dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by