Issue with table functions
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
jaclyn
am 9 Feb. 2021
Bearbeitet: Cris LaPierre
am 10 Feb. 2021
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 Kommentar
Cris LaPierre
am 9 Feb. 2021
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'}
Akzeptierte Antwort
jaclyn
am 10 Feb. 2021
1 Kommentar
Cris LaPierre
am 10 Feb. 2021
Bearbeitet: Cris LaPierre
am 10 Feb. 2021
It is very likely you are using the exact same version of MATLAB in both computers. You can check by running the ver command in the MATLAB command window. If that is the case, the install date does not matter. There may have been an issue with how MATLAB installed on your laptop. You could try reinstalling it. If the same thing happens, there may be an issue with file system on that laptop.
Weitere Antworten (2)
Steven Lord
am 9 Feb. 2021
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 Kommentare
Steven Lord
am 10 Feb. 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
am 10 Feb. 2021
1 Kommentar
Walter Roberson
am 10 Feb. 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
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!