MATLAB Answers

need solution during trainning

35 views (last 30 days)
NABARUN MAIKAP
NABARUN MAIKAP on 11 May 2020
Hello all, I am new in this community .I need help to solve the below problem. please help me..
statement : You can add a custom function at the end of your script. For data preprocessing, the function should take the data returned from the datastore as input. It should return the transformed data as output.
function dataout = functionName(datain)
% do something with datain
dataout = ...
end
Given script :
letterds = datastore("*_M_*.txt");
data = read(letterds);
data = scale(data);
plot(data.X,data.Y)
axis equal
plot(data.Time,data.Y)
ylabel("Vertical position")
xlabel("Time")
Task ; -
Create a function called scale at the end of the script that performs the following operations:
data.Time = (data.Time - data.Time(1))/1000;
data.X = 1.5*data.X;
Because these commands modify the variable data directly, your function should use data as both the input and output variable.
Note that the third line of the script calls the scale function. Your script won't run until this function has been created.
Also note that local functions must be at the end of a script. This means you will be editing the script sections out of order in this interaction. The section headings show which section of the script to edit in each task.
  3 Comments
Mritunjaya Sharma
Mritunjaya Sharma on 28 May 2020
To use a function as an input to another function, create a function handle by adding the @ symbol to the beginning of the function name.
transform(ds,@myfun)
A function handle is a reference to a function. Without the @ symbol, MATLAB will interpret the function name as a call to that function.
TaskUse the transform function to create a transformed datastore called preprocds. This datastore should apply the scale function to the data referenced by letterds.

Sign in to comment.

Answers (9)

Ravi kumar
Ravi kumar on 13 May 2020
letterds = datastore("*_M_*.txt");
data = read(letterds);
data.Time = (data.Time - data.Time(1))/1000;
data.X = 1.5*data.X;
plot(data.X,data.Y)
axis equal
plot(data.Time,data.Y)
ylabel("Vertical position")
xlabel("Time")
data = scale(data);
  1 Comment
Abhishek Nandeppagol
Abhishek Nandeppagol on 25 May 2020
Use the transform function to create a transformed datastore called preprocds. This datastore should apply the scale function to the data referenced by letterds.

Sign in to comment.


VISHAL
VISHAL on 30 May 2020
letterds = datastore("*_M_*.txt");
data = read(letterds);
data = scale(data);
plot(data.X,data.Y)
axis equal
plot(data.Time,data.Y)
ylabel("Vertical position")
xlabel("Time")
function data = scale(data)
data.Time = (data.Time - data.Time(1))/1000;
data.X = 1.5*data.X;
end

Hessel
Hessel on 1 Jun 2020
you should put the "sacle" function at the end
letterds = datastore("*_M_*.txt");
data = read(letterds);
data = scale(data);
plot(data.X,data.Y)
axis equal
plot(data.Time,data.Y)
ylabel("Vertical position")
xlabel("Time")
preprocds = transform(letterds,@scale)
function data = scale(data)
data.Time = (data.Time - data.Time(1))/1000;
data.X = 1.5*data.X;
end

Ali Al-nuaimi
Ali Al-nuaimi on 12 Jun 2020
preprocds = transform(letterds,@scale)
function data = scale(data)
data.Time = (data.Time - data.Time(1))/1000;
data.X = 1.5*data.X;
end

L.J.
L.J. on 13 Jun 2020
data = readall(preprocds);
plot(data.Time, data.Y)
The first line of code needs to be surpressed, so just be sure to add a ; to solve the issue :) good luck

Roshan karthick
Roshan karthick on 13 May 2020
letterds = datastore("*_M_*.txt");
data = read(letterds);
data = scale(data);
plot(data.X,data.Y)
axis equal
plot(data.Time,data.Y)
ylabel("Vertical position")
xlabel("Time")
  1 Comment
Ravi kumar
Ravi kumar on 13 May 2020
its wrong answer .i tried in matlab

Sign in to comment.


BRAJ KISHOR VERMA
BRAJ KISHOR VERMA on 28 May 2020
Edited: Walter Roberson on 15 Jun 2020
letterds = datastore("*_M_*.txt");
preprocds = transform(letterds,@scale)
data.Time = (data.Time - data.Time(1))/1000;
data.X = 1.5*data.X;
plot(data.X,data.Y)
axis equal
plot(data.Time,data.Y)
ylabel("Vertical position")
xlabel("Time")
data = scale(data);
in this we have a task
TASK
Use the readall function to import all the data. Check that the preprocessing function was applied to each file by plotting the Y variable as a function of Time.

Priti Gujar
Priti Gujar on 15 Jun 2020
Use the transform function to create a transformed datastore called preprocds. This datastore should apply the scale function to the data referenced by letterds.

Abdul Aziz Hisham Shubbak
Abdul Aziz Hisham Shubbak on 19 Apr 2021
last all ::
function data = scale(data)
data.Time = (data.Time - data.Time(1))/1000;
data.X = 1.5*data.X;
data.X = data.X - mean(data.X);
data.Y = data.Y - mean(data.Y);
end

Products

Community Treasure Hunt

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

Start Hunting!

Translated by