Writing data to readable workspace table
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I apologise, i am sure this is trivial but have struggled for a few hours with this.
I simply want to define some variables and constants, generate an associated table that is both saved to my hard drive and appears in a readable manner in my workspace. I have been using the "writetable" command but this is not doing what i want. Sure i can generate txt, xls files likes this but they are all single strings of numbers that cannot be read back in
A very simple example:
x=[0:0.1:10]
y=exp(x)
T=table(x,y)
writetable(T, 'jjdexp.txt')
load 'jjdexp.txt' - this line fails - can't read table as written
Basically , for two variables, for example, i want to generate a readable/loadable 2x1 table on my harddrive and workspace
any advice hugely welcome
Jason
2 Kommentare
Peter Perkins
am 5 Jun. 2023
Jason, I doubt that this
x=[0:0.1:10];
y=exp(x);
T=table(x,y)
is the table you want. I imagine you want
x=[0:0.1:10]';
y=exp(x);
T=table(x,y)
Tables are column-oriented, but they are able to hold variables that themselves have multiple columns.
Stephen23
am 5 Jun. 2023
And this:
x = [0:0.1:10];
is simply written like this, without the superfluous concatenation operator:
x = 0:0.1:10;
Antworten (1)
Cris LaPierre
am 7 Mai 2023
2 Kommentare
Walter Roberson
am 7 Mai 2023
When you load() a text file, and MATLAB is able to recognize it as a text file, then officially that form of load only supports files saved with save -ascii .
In practice, what load() of a text file supports is:
- empty lines are ignored (so there may be leading empty lines)
- If the line contains a % anywhere on the line, then from the % to the end of the line is ignored. For example 1% markup would be considered a valid entry of the number 1 with the % onward being ignored
- other than in comments, only number-forming-characters and comma and semi-colon are permitted. Quoted text is not permitted. Text (such as headers) is only permitted after % (that is, as a comment)
- commas and semi-colons may be used to separate columns
- there must be the same number of (not-commented) numeric columns on each line
- The letter designating a exponent may be e E d D
- Complex numbers immediately following another number with no space will be permitted but will be ignored. For example 1-3.7i will be treated as 1 with no error. i and j are both accepted for complex component indicator
- imaginary-only components will have the i or j immediately beside them, will be accepted but treated as real values. So for example 1 -3.7i 8.9 will be accepted as [1, -3.7, 8.9]
When you writetable() with the default options, variable names are emitted on the first line of the resulting output. Those variable names will very likely not happen to start with '%' and not happen to look like numbers (you can deliberately create tables with variables to get around this, but it would seldom happen naturally.) That row of variable names would then violate the rules about only-comments-and-numbers-and-delimiters and so not be accepted by load()
Siehe auch
Kategorien
Mehr zu Tables 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!