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 8854351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:51:39+00:00 2026-06-14T13:51:39+00:00

I currently have a MATLAB function that looks like this: function outfile=multi_read(modelfrom,modelto,type) models=[modelfrom:1:modelto]; num_models=length(models);

  • 0

I currently have a MATLAB function that looks like this:

function outfile=multi_read(modelfrom,modelto,type)

models=[modelfrom:1:modelto];
num_models=length(models);

model_path='../MODELS/GRADIENT/'

for id=1:num_models
    fn=[model_path num2str(models(id)) '/'];  %Location of file to be read
    outfile=model_read(fn,type);              %model_read is a separate function
end
end

The idea of this function is to execute another function model_read for a series of files, and output these files to the workspace (not to disk). Note that the output from model_read is a structure! I want the function to save the file to the workspace using sequential names, similar to typing:

file1=multi_read(1,1,x)
file2=multi_read(2,2,x)
file3=multi_read(3,3,x)
etc.

which would give file1, file2 and file3 in the workspace, but instead by recalling the command only once, something like:

multi_read(1,3,x)

which would give the same workspace output.

Essentially my questions is, how do I get a function to output variables with multiple names without having to recall the function multiple times.

  • 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-14T13:51:41+00:00Added an answer on June 14, 2026 at 1:51 pm

    As suggested in the comment I would try this approach which is more robust, at least IMHO:

        N = tot_num_of_your_files; %whatever it is          
    
        file = cellfun(@(i)multi_read(i,i,x),mat2cell(1:N,1,ones(1,N)),...
                             'UniformOutput' , false); %(x needs to be defined)
    

    You will recover objects by doing file{i}.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my program I have currently a piece of code that looks like this
I have been currently using a Matlab script that plots a function and prints
I have a Matlab function compiled into C library. I am using this library
I am currently writing a MEX function that will have to work with a
Currently have a drop down menu that is activated on a hover (from display:none
Currently have password protection on my main and sub directories, however I'd like to
I currently have a XSLT 2.0 Stylesheet that I am trying to remove empty
I currently have one project that currently contains multiple packages. These packages make up
I currently have a deployed app (fortworth.herokuapp.com) that I am attempting to sort movies
I currently have a MySQL table like: id | friend 1 | 2 1

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.