SlideShare a Scribd company logo
1 of 2
How do I transfer this m-file to make it into a Function m-file in MATLAB? This is the only
thing i have left before i turn in my project, if you can help me clear this up i would appreciate it.
clear all;
a=input('Enter any desired row vector in []:');
n=length(a);
for ii=1:n
fprintf('ii = %d  ', ii);
for jj = 1:n
fprintf(' jj = %d  ', jj);
for kk=1:n
fprintf(' kk = %d  ', kk);
A(ii,jj)= a(ii)*a(jj)*a(kk);
end
end
end
A
plot(A)
I keep getting these errors:
Line 1: Invalid syntax at 'Enter any desired row vector in []:'. Possibly, a ), } , or ] is missing.
Line 1: Parse error at ')' : usage might be invalid MATLAB syntax
! Line 1: The function return value 'a' might be unset.
Solution
ANSWER:
To convert a piece of code into a function to which parameters can be passed the folowing is the
syntax to be used.
function func_name(variable) where func_name is the name of the function we intend to keep
and variable is the variable to be passed to the function.
function assignment(a)
clear all;
n=length(a);
for ii=1:n
fprintf('ii = %d  ', ii);
for jj = 1:n
fprintf(' jj = %d  ', jj);
for kk=1:n
fprintf(' kk = %d  ', kk);
A(ii,jj)= a(ii)*a(jj)*a(kk);
end
end
end
plot(A);
The above change has to be incorporated.

More Related Content

Similar to How do I transfer this m-file to make it into a Function m-file in MAT.docx

CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docxCSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
mydrynan
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
gilpinleeanna
 

Similar to How do I transfer this m-file to make it into a Function m-file in MAT.docx (20)

Matlab-3.pptx
Matlab-3.pptxMatlab-3.pptx
Matlab-3.pptx
 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
 
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docxCSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
 
Matlab practice
Matlab practiceMatlab practice
Matlab practice
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
 
Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Basics of MATLAB programming
Basics of MATLAB programmingBasics of MATLAB programming
Basics of MATLAB programming
 
6 weeks summer training in matlab,jalandhar
6 weeks summer training in matlab,jalandhar6 weeks summer training in matlab,jalandhar
6 weeks summer training in matlab,jalandhar
 
data mining training in Bangalore
data mining training in Bangaloredata mining training in Bangalore
data mining training in Bangalore
 
6months industrial training in matlab, jalandhar
6months industrial training in matlab, jalandhar6months industrial training in matlab, jalandhar
6months industrial training in matlab, jalandhar
 
vlsi training in chandigarh
vlsi training in chandigarhvlsi training in chandigarh
vlsi training in chandigarh
 
Matlab tut2
Matlab tut2Matlab tut2
Matlab tut2
 
MATLAB guide
MATLAB guideMATLAB guide
MATLAB guide
 
Intro to matlab
Intro to matlabIntro to matlab
Intro to matlab
 

More from cliftonl1

How is communication a part of best practices-Solution4 Leadership Bes.docx
How is communication a part of best practices-Solution4 Leadership Bes.docxHow is communication a part of best practices-Solution4 Leadership Bes.docx
How is communication a part of best practices-Solution4 Leadership Bes.docx
cliftonl1
 
How does the National Society of Professional Engineers Code of Ethics.docx
How does the National Society of Professional Engineers Code of Ethics.docxHow does the National Society of Professional Engineers Code of Ethics.docx
How does the National Society of Professional Engineers Code of Ethics.docx
cliftonl1
 
How do I determine the Rf Value with just the information I have provi.docx
How do I determine the Rf Value with just the information I have provi.docxHow do I determine the Rf Value with just the information I have provi.docx
How do I determine the Rf Value with just the information I have provi.docx
cliftonl1
 
How do I print a list of payroll checks for the calendar year to date.docx
How do I print a list of payroll checks for the calendar year to date.docxHow do I print a list of payroll checks for the calendar year to date.docx
How do I print a list of payroll checks for the calendar year to date.docx
cliftonl1
 
How does SO2 in the atmosphere affect global warming- In general- what.docx
How does SO2 in the atmosphere affect global warming- In general- what.docxHow does SO2 in the atmosphere affect global warming- In general- what.docx
How does SO2 in the atmosphere affect global warming- In general- what.docx
cliftonl1
 
how do the different architectures of a polymer affect their propertie.docx
how do the different architectures of a polymer affect their propertie.docxhow do the different architectures of a polymer affect their propertie.docx
how do the different architectures of a polymer affect their propertie.docx
cliftonl1
 
how would a police department exhibit different structure and procedur.docx
how would a police department exhibit different structure and procedur.docxhow would a police department exhibit different structure and procedur.docx
how would a police department exhibit different structure and procedur.docx
cliftonl1
 

More from cliftonl1 (20)

How many dance steps would the square have-and-Construct a multiplicat.docx
How many dance steps would the square have-and-Construct a multiplicat.docxHow many dance steps would the square have-and-Construct a multiplicat.docx
How many dance steps would the square have-and-Construct a multiplicat.docx
 
How has the physician-patient relationship changed over the past centu.docx
How has the physician-patient relationship changed over the past centu.docxHow has the physician-patient relationship changed over the past centu.docx
How has the physician-patient relationship changed over the past centu.docx
 
How is treasury stock shown on the balance sheet- Treasury stock is no.docx
How is treasury stock shown on the balance sheet- Treasury stock is no.docxHow is treasury stock shown on the balance sheet- Treasury stock is no.docx
How is treasury stock shown on the balance sheet- Treasury stock is no.docx
 
How is repetition of components different from redundancy- How are the.docx
How is repetition of components different from redundancy- How are the.docxHow is repetition of components different from redundancy- How are the.docx
How is repetition of components different from redundancy- How are the.docx
 
How is communication a part of best practices-Solution4 Leadership Bes.docx
How is communication a part of best practices-Solution4 Leadership Bes.docxHow is communication a part of best practices-Solution4 Leadership Bes.docx
How is communication a part of best practices-Solution4 Leadership Bes.docx
 
How does the National Society of Professional Engineers Code of Ethics.docx
How does the National Society of Professional Engineers Code of Ethics.docxHow does the National Society of Professional Engineers Code of Ethics.docx
How does the National Society of Professional Engineers Code of Ethics.docx
 
how does cinchona catalyst workSolutionCatalyst working- 1) Catalyst i.docx
how does cinchona catalyst workSolutionCatalyst working- 1) Catalyst i.docxhow does cinchona catalyst workSolutionCatalyst working- 1) Catalyst i.docx
how does cinchona catalyst workSolutionCatalyst working- 1) Catalyst i.docx
 
How does the evolution of attack tools affect existing systems- What s.docx
How does the evolution of attack tools affect existing systems- What s.docxHow does the evolution of attack tools affect existing systems- What s.docx
How does the evolution of attack tools affect existing systems- What s.docx
 
How do you think the DATA Act will impact governmental entities and st.docx
How do you think the DATA Act will impact governmental entities and st.docxHow do you think the DATA Act will impact governmental entities and st.docx
How do you think the DATA Act will impact governmental entities and st.docx
 
How do I determine the Rf Value with just the information I have provi.docx
How do I determine the Rf Value with just the information I have provi.docxHow do I determine the Rf Value with just the information I have provi.docx
How do I determine the Rf Value with just the information I have provi.docx
 
How do I print a list of payroll checks for the calendar year to date.docx
How do I print a list of payroll checks for the calendar year to date.docxHow do I print a list of payroll checks for the calendar year to date.docx
How do I print a list of payroll checks for the calendar year to date.docx
 
How does SO2 in the atmosphere affect global warming- In general- what.docx
How does SO2 in the atmosphere affect global warming- In general- what.docxHow does SO2 in the atmosphere affect global warming- In general- what.docx
How does SO2 in the atmosphere affect global warming- In general- what.docx
 
How does an awareness of the historical link between the United States.docx
How does an awareness of the historical link between the United States.docxHow does an awareness of the historical link between the United States.docx
How does an awareness of the historical link between the United States.docx
 
How do you utilize PM software to manage team activities-SolutionProje.docx
How do you utilize PM software to manage team activities-SolutionProje.docxHow do you utilize PM software to manage team activities-SolutionProje.docx
How do you utilize PM software to manage team activities-SolutionProje.docx
 
how do the different architectures of a polymer affect their propertie.docx
how do the different architectures of a polymer affect their propertie.docxhow do the different architectures of a polymer affect their propertie.docx
how do the different architectures of a polymer affect their propertie.docx
 
How do phospholipid bilayers maintain specific concentrations of solut.docx
How do phospholipid bilayers maintain specific concentrations of solut.docxHow do phospholipid bilayers maintain specific concentrations of solut.docx
How do phospholipid bilayers maintain specific concentrations of solut.docx
 
how would a police department exhibit different structure and procedur.docx
how would a police department exhibit different structure and procedur.docxhow would a police department exhibit different structure and procedur.docx
how would a police department exhibit different structure and procedur.docx
 
How will you close your knowledge gap- Is your mind geared to re-think.docx
How will you close your knowledge gap- Is your mind geared to re-think.docxHow will you close your knowledge gap- Is your mind geared to re-think.docx
How will you close your knowledge gap- Is your mind geared to re-think.docx
 
How to do web application testing on a website checking it-'s (Functio.docx
How to do web application testing on a website checking it-'s (Functio.docxHow to do web application testing on a website checking it-'s (Functio.docx
How to do web application testing on a website checking it-'s (Functio.docx
 
How to make a Mic 1 L2 instruction set that takes in user input throug.docx
How to make a Mic 1 L2 instruction set that takes in user input throug.docxHow to make a Mic 1 L2 instruction set that takes in user input throug.docx
How to make a Mic 1 L2 instruction set that takes in user input throug.docx
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 

How do I transfer this m-file to make it into a Function m-file in MAT.docx

  • 1. How do I transfer this m-file to make it into a Function m-file in MATLAB? This is the only thing i have left before i turn in my project, if you can help me clear this up i would appreciate it. clear all; a=input('Enter any desired row vector in []:'); n=length(a); for ii=1:n fprintf('ii = %d ', ii); for jj = 1:n fprintf(' jj = %d ', jj); for kk=1:n fprintf(' kk = %d ', kk); A(ii,jj)= a(ii)*a(jj)*a(kk); end end end A plot(A) I keep getting these errors: Line 1: Invalid syntax at 'Enter any desired row vector in []:'. Possibly, a ), } , or ] is missing. Line 1: Parse error at ')' : usage might be invalid MATLAB syntax ! Line 1: The function return value 'a' might be unset. Solution ANSWER: To convert a piece of code into a function to which parameters can be passed the folowing is the syntax to be used. function func_name(variable) where func_name is the name of the function we intend to keep and variable is the variable to be passed to the function.
  • 2. function assignment(a) clear all; n=length(a); for ii=1:n fprintf('ii = %d ', ii); for jj = 1:n fprintf(' jj = %d ', jj); for kk=1:n fprintf(' kk = %d ', kk); A(ii,jj)= a(ii)*a(jj)*a(kk); end end end plot(A); The above change has to be incorporated.