Issue with table functions
Mostrar comentarios más antiguos
Hi, I had some table code working until recently, I now can't import tables (from some searching this is possible due to a microsoft update. gah). I was working around an issue using table import to create a table with my desired headings and one row of data. As I can't do this anymore I need to solve original problem.
I have some data as an array that I want to stick in a table with set heading and then append some columns. I'm having issues with renaming variables or adding to a blank table. Simple, example code:
results=magic(5);
T1=array2table(results);
T1.Properties.VariableNames = {'a','b','c','d','e'};
Firstly, if I try and run this I get "Too many input arguments" error. I have also tried renaming within a loop with same error. As I also want to append some columns, I've also tried.
T2= cell2table(cell(0,7), 'VariableNames', {'rndm','target','a','b','c','d','e'});
T2.a=T1.results1; %%or
T2.a(:,1)=results(:,1);
T2.rndm(1,1)='no';
I am also getting ""Too many input arguments"
Again, I've seen posts with this sort of code working, e.g.
vnames = {'Exp', 'Strike', 'Put_Mark', 'Put_Ask', 'Put_Bid', 'Put_Delta', 'Put_ImplVol', 'Date', 'DateNM'};
optionsChange = array2table(zeros(0,9), 'VariableNames',vnames);
optionsChange.Date = zeros(1,3); % simple way to get a 0x1 datetime
optionsChange.DateNM = datetime(zeros(1,3));
summary(optionsChange)
This code does not work for me also, with the same error. Is this a bug? I'm using R2019b and slightly reticent to update just at the mo as I'm half way through a project with a lot of additional package installs. I also don't know why table code that was working three weeks ago has stopped working (mocrosoft update?!).
If anyone could offer help on getting an array of doubles in a table, with renamed varname and then appending text and doubles columns I'd be very grateful.
Thank you. Jac
1 comentario
Your first bit of code works for me. Try clearing your workspace?
results=magic(5);
T1=array2table(results);
T1.Properties.VariableNames = {'a','b','c','d','e'}
Respuesta aceptada
Más respuestas (2)
Steven Lord
el 9 de Feb. de 2021
0 votos
Can you show us the full and exact text of the error message you're receiving? Not just the "Too many input arguments" part but everything shown in red and/or orange when you run that code? Knowing not just what error occurs but where it occurs may help us determine the cause of the error.
If I had to guess I'd say you'd written a table.m file that was taking precedence over the table function included in MATLAB, and your table.m accepted fewer inputs than the table function, but that's just an educated guess.
5 comentarios
jaclyn
el 10 de Feb. de 2021
jaclyn
el 10 de Feb. de 2021
Walter Roberson
el 10 de Feb. de 2021
Try
restoredefaultpath; rehash toolboxcache
and see if that works for you.
If not, then please send us the output of
ls
showing which files are in your current directory, so that we can check for potential conflicts. For example tabularDimensions/setlabels can have problems if you have your own isstring.m
Steven Lord
el 10 de Feb. de 2021
I doubt the message "Too many input arguments" is the entire error message you receive. For instance, if I make a mistake in a call to ode45:
>> ode45(@(t, y) y.', [0, 10], [1; 2])
Error using odearguments (line 93)
@(T,Y)Y.' must return a column vector.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Everything after the first line of that copied text is displayed in red in the Command Window. It points me to specific lines in ode45 and a helper function odearguments. That information will be helpful in determining where the problem actually occurs, which may suggest a next step for diagnosing the cause of the error.
jaclyn
el 10 de Feb. de 2021
jaclyn
el 10 de Feb. de 2021
0 votos
1 comentario
Walter Roberson
el 10 de Feb. de 2021
At the command line, command
dbstop if caught error
A=magic(5); %works
age=(A(:,1)); %works
T=table(age); %works
T.Properties.VariableNames = {'height'};
It should stop at the actual error location; at that point please show us the line it had the problem with, and show us
dbstack
I am expecting that the problem will be near function setlabels in file tabularDimensions
Categorías
Más información sobre Introduction to Installation and Licensing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!