Clear Filters
Clear Filters

CurveFitter tool doesn't load tables after they have been transposed using rows2vars

1 view (last 30 days)
Hi,
I have data stored in a variable "data", which is an 11x22 table. CurveFitter loads its columns just fine, but I need it to load individual rows, not columns.
When I use Tdata = rows2vars(data), which returns the desired 22x12 table, curveFitter doesn't load Tdata. The dropdown menu doesn't give me the option to select Tdata, and if I manually enter it, it'll just revert back to "select".
Since this feels like a bug to me, I was just wondering if this is a known issue or if I'm doing something wrong? I'm using Matlab R2023b.

Accepted Answer

Garmit Pant
Garmit Pant on 8 Jul 2024
Hello Nick
From what I gather, you are trying to fit data to a curve using the Curve Fitter App and you are pre-processing the data to fit the row data using “rows2vars” function.
Curve Fitter App expects numeric data as the input for the ‘X data’ and the ‘Y data’ selection menus. For tables, it automatically identifies the valid columns. For ex. If the table ‘data’ is of the size 11x22 with all the columns having numeric data but column 11 having character data, the Curve Fitter App will let you select all the columns from the ‘data’ table except column 11.
Given that you can see columns from your variable ‘data’, here are some possible scenarios that might explain the behavior you have encountered:
  • One of the columns of ‘data’ has entries of datatype ‘char’: In this case, when the table is converted using the “rows2vars” function, the conversion between ‘char’ and numeric datatypes is unsuccessful and the new table is formed with empty entries except for the row with ‘char’ entries. The following code snippet demonstrates this:
data = array2table(rand(11,22)); % Create an 11x22 table with random data
data.Var11 = repmat('a', 11, 1);
Tdata = rows2vars(data)
Tdata = 22x12 table
OriginalVariableNames Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11 _____________________ ____ ____ ____ ____ ____ ____ ____ ____ ____ _____ _____ {'Var1' } {'Var2' } {'Var3' } {'Var4' } {'Var5' } {'Var6' } {'Var7' } {'Var8' } {'Var9' } {'Var10'} {'Var11'} a a a a a a a a a a a {'Var12'} {'Var13'} {'Var14'} {'Var15'} {'Var16'}
  • One of the columns of ‘data’ has entries of cell or string entries: In this case, the “rows2vars” converts all the entries into cells or strings. The following code snippet demonstrates this:
data = array2table(rand(11,22)); % Create an 11x22 table with random data
data.Var11 = repmat({'a'}, 11, 1);
Tdata = rows2vars(data);
columnDataTypes = varfun(@class, data, 'OutputFormat', 'cell');
% Display the data types
disp('Data Types of All Columns of data:');
Data Types of All Columns of data:
for i = 1:width(data)
fprintf('%s: %s\n', data.Properties.VariableNames{i}, columnDataTypes{i});
end
Var1: double Var2: double Var3: double Var4: double Var5: double Var6: double Var7: double Var8: double Var9: double Var10: double Var11: cell Var12: double Var13: double Var14: double Var15: double Var16: double Var17: double Var18: double Var19: double Var20: double Var21: double Var22: double
columnTDataTypes = varfun(@class, Tdata, 'OutputFormat', 'cell');
% Display the data types
disp('Data Types of All Columns of Tdata:');
Data Types of All Columns of Tdata:
for i = 1:width(Tdata)
fprintf('%s: %s\n', Tdata.Properties.VariableNames{i}, columnTDataTypes{i});
end
OriginalVariableNames: cell Var1: cell Var2: cell Var3: cell Var4: cell Var5: cell Var6: cell Var7: cell Var8: cell Var9: cell Var10: cell Var11: cell
Kindly check the datatypes of the entries in the table ‘data’. Due to mismatch of datatypes, the resultant converted table ‘Tdata’ might not contain any numeric column and thus the Curve Fitter App does not identify its columns.
For further understanding, kindly refer to the following MathWorks Documentation:
  1. Refer to the ‘Select Data to Fit in Curve Fitter App’ section to understand the expected datatypes: https://www.mathworks.com/help/releases/R2023b/curvefit/data-selection.html
  2. fit” function to programmatically fit data to a curve: https://www.mathworks.com/help/releases/R2023b/curvefit/fit.html
I hope you find the above explanation and suggestions useful!
  2 Comments
Nick
Nick on 8 Jul 2024
Thank you, that is exactly what happened. My data was imported from an excel spreadsheet, with one column being a description in string format. So rows2vars caused all entries to become cells. I had noticed the strings in the data and removed them, but didn't realize that all entries became cells in the process. Thanks a lot, to both of you. This almost drove me crazy over the weekend.

Sign in to comment.

More Answers (0)

Categories

Find more on Curve Fitting Toolbox in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!