Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8430521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:36:50+00:00 2026-06-10T05:36:50+00:00

In Octave I would like to save a struct to a textfile where the

  • 0

In Octave I would like to save a struct to a textfile where the name of the file is decided during the runtime of the script. With my approach I always get an error:

expecting all arguments to be strings. 

(For a fixed filename this works fine.) So how to save a struct to a file using a variable filename?

clear all;
myStruct(1).resultA = 1;
myStruct(1).resultB = 2;
myStruct(2).resultA = 3;
myStruct(2).resultB = 4;

variableFilename = strftime ("result_%Y-%m-%d_%H-%M.mat", localtime(time()))

save fixedFilename.mat myStruct; 
% this works and saves the struct in fixedFilename.mat

save( "-text", variableFilename, myStruct); 
% this gives error: expecting all arguments to be strings
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:36:52+00:00Added an answer on June 10, 2026 at 5:36 am

    In Octave, When using save as a function you need to do something like this:

    myfilename = "stuff.txt";
    mystruct = [ 1 2; 3 4]
    save("-text", myfilename, "mystruct");
    

    The above code will create a stuff.txt file and the matrix data is put in there.

    The above code will only work when mystruct is a matrix, if you have a cell of strings, it will fail. For those, you can roll your own:

     xKey = cell(2, 1);
     xKey{1} = "Make me a sandwich...";
     xKey{2} = "OUT OF BABIES!";
     outfile = fopen("something.txt", "a");
     for i=1:rows(xKey),
       fprintf(outfile, "%s\n", xKey{i,1});
     end
     fflush(outfile);
     fclose(outfile);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to save and load a set of images in Octave /
I would like to get an invertible matrix in Octave but as integers matrix,
I would like to add two vectors with different lengths in Matlab or Octave.
I have developed a program in Octave to which I would like to add
I would like to start an octave session within a restricted bash shell, or
In Matlab or GNU Octave I'd like to do something like this: x=struct('a',1,'b',2,'c',[1 2;3
I am a beginning Octave user and would like to compute all the integer
I would like to calculate the following symbolic expression in GNU Octave: int(exp(ikx-|k|^n),k,-infinity,infinity) ,
I have two column of data and would like to plot using octave. I
Today, as I tried to put together a script in Octave, I thought, this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.