How to call a function containing large dataset of inputs and targe... (2024)

16 views (last 30 days)

Show older comments

Divye on 12 Jun 2024 at 12:41

  • Link

    Direct link to this question

    https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl

  • Link

    Direct link to this question

    https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl

Edited: Aquatris about 16 hours ago

Open in MATLAB Online

function y=RefGen(u1,u2)

[u1,u2,yd]=dsdata();

x=[u1 u2];

Here u1 and u2 are inputs and y is the output,

dsdata() is the function to be called in the matlab function block

u1 and u2 will assign the input vectors containing 100 samples each and yd will assign the target attribute

x is the input matrix containing u1 and u2 inputs

4 Comments

Show 2 older commentsHide 2 older comments

Aquatris on 12 Jun 2024 at 13:00

Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl#comment_3185106

  • Link

    Direct link to this comment

    https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl#comment_3185106

Edited: Aquatris on 12 Jun 2024 at 13:00

Open in MATLAB Online

Your question is ambigous and your code is not clear.You give u1 and u2 as input to RefGen function but then overwrite them with the output from the dsdata function. What exactly are you trying to achieve?

As your code does, you can call a function from within another functions;

y = myFun_1(5);

function 1 called!function 2 called!

disp(y)

125

function y = myFun_1(x)

fprintf('function 1 called!\n')

y = 5*myFun_2(x);

end

function y = myFun_2(x)

fprintf('function 2 called!\n')

y = 5*x;

end

Divye on 13 Jun 2024 at 13:20

Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl#comment_3185931

  • Link

    Direct link to this comment

    https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl#comment_3185931

Actually dsdata()=[G T MPPT]

where each G,T,MPPT contain 100 samples i.e. 100 rows and 1 column each. I have to call this dataset and store these values in [u1,u2,yd] this implies [u1,u2,yd]=[G T MPPT]

Aquatris on 13 Jun 2024 at 13:51

Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl#comment_3185951

  • Link

    Direct link to this comment

    https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl#comment_3185951

Edited: Aquatris about 16 hours ago

Open in MATLAB Online

Since you mention dataset, is dsdata a '.mat' file or a function that outputs the G T MPPT arrays?

% if dsdata is a mat file with G T MPPT variable inside

function [u1,u2,yd]=RefGen(u1,u2)

data = load('dsdata.mat');

u1 = data.G;

u2 = data.T;

end

% if dsdata is a function that outputs G T MPPT

function [u1,u2,yd]=RefGen(u1,u2)

[G,T,MPPT] = dsdata;

u1 = G;

u2 = T;

yd = MPPT;

end

Divye on 13 Jun 2024 at 20:05

Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl#comment_3186196

  • Link

    Direct link to this comment

    https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl#comment_3186196

Thanks for your answer. The RefGen(u1,u2) function is written in the matlab function block.But where the dataset or dsdata() should be written as each of G,T,MPPT contain 100 samples

Sign in to comment.

Sign in to answer this question.

Answers (1)

Nipun on 13 Jun 2024 at 6:16

  • Link

    Direct link to this answer

    https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl#answer_1471311

  • Link

    Direct link to this answer

    https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl#answer_1471311

Open in MATLAB Online

Hi Divye,

I understand that you want to call a function dsdata that provides a large dataset of inputs and target attributes within a MATLAB Function block. Here's a concise example of how you can achieve this:

  1. Ensure dsdata is correctly defined and accessible within your MATLAB path.
  2. Modify your MATLAB Function block code to properly handle the large dataset.

Here's how you can structure your function:

function y = RefGen(u1, u2)

% Call the dsdata function to get input and target data

[u1, u2, yd] = dsdata();

% Combine inputs into a single matrix

x = [u1 u2];

% Here you can define how you want to process the inputs

% For demonstration, let's assume y is computed as the mean of the target

y = mean(yd);

end

Notes:

  1. dsdata Function: Ensure dsdata returns the dataset in the required format.
  2. Handling Large Data: If your dataset is extremely large, consider optimizing memory usage or processing data in chunks.

Example dsdata Function:

function [u1, u2, yd] = dsdata()

% Example dataset generation

u1 = rand(100, 1); % Replace with actual data

u2 = rand(100, 1); % Replace with actual data

yd = rand(100, 1); % Replace with actual target data

end

Including in MATLAB Function Block:

  1. Open your Simulink model.
  2. Insert a MATLAB Function block.
  3. Double-click the MATLAB Function block to open the editor.
  4. Replace the content with the RefGen function code above.
  5. Ensure dsdata is either in the same directory or in the MATLAB path.

For detailed guidance on using MATLAB Function blocks, refer to the MathWorks documentation: https://www.mathworks.com/help/simulink/ug/adding-data-to-a-matlab-function-block.html

Hope this helps.

Regards,

Nipun

1 Comment

Show -1 older commentsHide -1 older comments

Divye on 13 Jun 2024 at 19:14

Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl#comment_3186176

  • Link

    Direct link to this comment

    https://in.mathworks.com/matlabcentral/answers/2127901-how-to-call-a-function-containing-large-dataset-of-inputs-and-target-attribute-in-matlab-function-bl#comment_3186176

Thanks for your answer. i want to know that where to write the dsdata() function in the simulink and how to handle large dataset. I didn't get your 5th point and that you have written in notes. May you provide with some example.

The dataset contains dsdata()=[G T MPPT].where G and T are inputs and MPPT is the target attribute. Each of G,T,MPPT contain 100 samples .

Sign in to comment.

Sign in to answer this question.

See Also

Tags

  • solar pv mppt
  • matlab
  • simulink
  • ann
  • neural network simulink in matlab

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


How to call a function containing large dataset of inputs and targe... (8)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

How to call a function containing large dataset of inputs and targe... (2024)
Top Articles
Latest Posts
Article information

Author: Virgilio Hermann JD

Last Updated:

Views: 6482

Rating: 4 / 5 (41 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Virgilio Hermann JD

Birthday: 1997-12-21

Address: 6946 Schoen Cove, Sipesshire, MO 55944

Phone: +3763365785260

Job: Accounting Engineer

Hobby: Web surfing, Rafting, Dowsing, Stand-up comedy, Ghost hunting, Swimming, Amateur radio

Introduction: My name is Virgilio Hermann JD, I am a fine, gifted, beautiful, encouraging, kind, talented, zealous person who loves writing and wants to share my knowledge and understanding with you.