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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:19:57+00:00 2026-05-21T05:19:57+00:00

How can I convert this script into a MATLAB function? clear all; set={AB02XY_1,ZT99ER_1,UI87GP_1}; fileData1

  • 0

How can I convert this script into a MATLAB function?

clear all;

set={AB02XY_1,ZT99ER_1,UI87GP_1};

fileData1 = load([fileString set{1} '.mat']);  
fileData2 = load([fileString set{2} '.mat']);  
fileData3 = load([fileString set{3} '.mat']);  

[A,B] = myfunction1_1(fileData1,fileData2,fileData3);

fileName = 'C:\Users\Documents\MATLAB\matrice_AAA001.mat';  
save(fileName,'A','B');

clear all;  

set={AB02XY_2,ZT99ER_2,UI87GP_2};

fileData1 = load([fileString set{1} '.mat']);  
fileData2 = load([fileString set{2} '.mat']);  
fileData3 = load([fileString set{3} '.mat']);  

fileData4 = load('C:\Users\Documents\MATLAB\matrice_AAA001.mat');

[A,B] = myfunction1_2(fileData1,fileData2,fileData3,fileData4);

fileName = 'C:\Users\Documents\MATLAB\matrice_AAA001.mat';  
save(fileName,'A','B');

I do processing on large data files, then to avoid the error ‘out of memory ‘, I split each file into two parts and I use at the beginning of each stage ‘clear all’. So, what I want is to have a function as AAA001 = function (AB02XY, ZT99ER, UI87GP, MyFunction1).
my problem is that I have to write the same script for other data files. So, is there a way to build a function where I can just change the file names AB02XY, ZT99ER, UI87GP, and the name of the function used ‘MyFunction1’ for the sub-processing to get on the last step the file AAA001.

NB: I simplified my script, but actually I divide each file into 5 parts. So I want to transform the 5 parts of my script in a single function!!!

Thank you for your help.

  • 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-05-21T05:19:58+00:00Added an answer on May 21, 2026 at 5:19 am

    Here’s one way to do this. Call the function

     output = function ({'AB02XY', 'ZT99ER', 'UI87GP'}, 5, MyFunction1);
    

    Note that I assume that you want 5 file parts

    function out = myMainFunction(fileList, nParts, fun2run)
    %# myMainFunction calculates output from multiple split files
    %
    %# SYNOPSIS out = myMainFunction(fileList, nParts, fun2run)
    %#
    %# INPUT    fileList: cell array with file body names, e.g.
    %#                    'AB02XY' for files like 'AB02XY_1.mat'
    %#          nParts  : number of parts in which the files are split
    %#          fun2run : function handle or name. Function has to 
    %#                    accept lenght(fileList) arguments plus one
    %#                    that is the output of the previous iteration
    %#                    which is passed as a structure with fields A and B
    %#
    %# OUTPUT   out : whatever the function returns
    %#
    %# Brought to you by your friends from SO
    
    
    %# input checking should go here
    
    if ischar(fun2run)
       fun2run = str2func(fun2run);
    end
    
    nFiles = length(fileList);
    
    
    for iPart = 1:nParts
    
    data = cell(nFiles,1);
    for iFile=1:nFiles
    
    data{iFile} = load(sprintf(%s_%i.mat',fileList{iFile},iPart));
    
    end
    
    if iPart == 1
       %# call fun2run with nFiles inputs
       [out.A,out.B] = fun2run(data{:});
    else
       %# fun2run wants the previous output as well
       [out.A,out.B] = fun2run(data{:},out);
    end
    
    end %# loop parts
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i convert this to a decimal in SQL? Below is the equation
There's this program, pdftotext, that can convert a pdf file to a text file.
Can somebody advise me what this code does and how can I convert it
Is there any function like php's mb_convert_encoding which can convert an encoding to another?
Can I convert a string representing a boolean value (e.g., 'true', 'false') into an
Can we convert a hex string to a byte array using a built-in function
I am getting document.getElementById(#toHide) is null. How can solve this? how to convert this
I'm trying to convert a function from Javascript to CoffeeScript. This is the code:
I am using this script to parse HTML tags in order to convert them
I need an encoder that can convert mp3 files to he-aac (aka aac+). So

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.