Translate

MATLAB - Applying a function for each element in an array using arrayfun

I'm not a big matlab fan. For a project I needed to apply a function for each element in an array. For that arrayfun can be used.

Here is a simple example.

Say you have 3 arrays as follows.

A = [1,2,3,4]
B = [5,6,7,8]
C = [9,10,11,12]

And you need to calculate the value of a function myf, for A[i], B[i] and C[i] (i=1,2,3,4) which returns A[i] x B[i] + C[i]

You can do it as follows.

First define your function considering a single element.

function output=myf(a,b,c)
  output=a*b + c;
end

Then,

A = [1,2,3,4]
B = [5,6,7,8]
C = [9,10,11,12]

D = arrayfun(@myf,A,B,C)


Remember to have "@" before myf. It denotes a handle in matlab. If you forget it, matlab will try to evaluate the function instead of considering its handle, which may result in "Not enough input arguments" error.



55 comments:

  1. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in MATLAB, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on MATLAB. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Nitesh Kumar
    MaxMunus
    E-mail: nitesh@maxmunus.com
    Skype id: nitesh_maxmunus
    Ph:(+91) 8553912023
    http://www.maxmunus.com/




    ReplyDelete
  2. It's very happy to visit your site and very Excellent to read all the concepts...Very Thankful for all your Efforts...
    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

    ReplyDelete
  3. prefer to study this kind of material. Nicely written information in this post, the quality of content is fine and the conclusion is lovely. Things are very open and intensely clear explanation of issue
    Java training
    FullStack development training
    AWS Training courses and certification

    ReplyDelete
  4. DevOps Practitioner training and certification with NovelVIsta is designed by mentors who have been setting up the DevOps trends in so many organizations. Our trainers use creative methodologies to keep the participants’ level of interest growing.

    Devops Training in Gurgaon

    ReplyDelete
  5. Have had a great experience. Love the quality of their study material. Had a good class room training . The executives are helpful. Have completed my certification successfull.
    Data Science Training in Gurgaon
    Machine Learning Training in Gurgaon
    Devops Training in Gurgaon
    Python Training in Gurgaon

    ReplyDelete
  6. Are you looking for AWS Training in delhi? AP2V Academy is the best option for you! We are one of the best AWS Training provider academies in Delhi, India. We Also conduct DevOps Training, devops Training, GCP Course, Linux Courses training, etc. Online live interactive classrooms with lifetime recording videos & 24*7 support. For more information- 92103 33323.

    ReplyDelete
  7. Are you looking for AWS Training in Gurgaon? AP2V Academy is the best option for you! We are one of the best AWS Training provider academies in Gurgaon, India. We Also conduct DevOps Training, DevOps Training, GCP courses, Linux Courses training, etc. Online live interactive classrooms with lifetime recording videos & 24*7 support. For more information- 92103 33323.

    ReplyDelete

  8. Are you looking for Python Training in Gurgaon? AP2V Academy is the best option for you! We are one of the best Python Training provider academies in Gurgaon, India. We Also conduct DevOps Training, GCP courses, Linux Courses training, AWS Training etc. Online live interactive classrooms with lifetime recording videos & 24*7 support. For more information- 92103 33323.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. Looking for a family practice doctor in Vienna? Heale Medical has you covered. Our team of family practice doctors in Vienna is committed to providing you with top-notch care. We've got you covered whether you're looking for a general practitioner or pediatrician.

    ReplyDelete

  11. The best water park in Gurgaon AppuGhar is one of the best waterparks to enjoy the most amazing and trending water slides and spread across an area of 10 acres,

    ReplyDelete
  12. Best Eye clinic in Gurgaon Barmen Eye Care clinic is a premier, multispecialty eye hospital in Gurgaon where we offer the world-class latest diagnostic and surgical technologies.

    ReplyDelete
  13. Want to know more about the ACCA Subjects and what will be the syllabus like Business and Technology, Management Accounting and Financial Accounting you will gonna learn all about this topics in this blog Click here To learn more

    ReplyDelete

  14. Book New Projects in Gurgaon, you can buy all pre-launch, under construction, or upcoming projects and property at a relevant price in the second largest city of Haryana.

    ReplyDelete
  15. Appu Ghar provides a low price for oyster water park tickets booking online . Get the best Deals & offer on Online tickets Booking at AppuGhar Gurgaon. Book Now.

    ReplyDelete
  16. Looking for an online astrologer in Gurgaon? Look no further than Mahakali Jyotish Kendra. Our experienced astrologers can answer all of your questions about love, career, and more. Contact us today!

    ReplyDelete


  17. Barmen Eyecare is One of the best Eye Care Clinic in Gurgaon, we have the most experienced eye surgeons Team. We have the Best technology, and painless treatments with hight class equipment

    ReplyDelete
  18. Looking for the latest treatment for dry eye Syndrome in Gurgaon you are facing problems in wearing contact, driving at night, and Reddening of eyes. No worry Barman EyeCare Can solve all your dry eye-related problems

    ReplyDelete
  19. Do you want to know about the IFRS Certification Course and CIMA or you want to know why do we need to get this qualification and how it will help you to grow your future.

    ReplyDelete
  20. Are you Looking For a good Commercial Space in Gurgaon For your Office use. your search is Over now Reias India is providing the best Commercial property at good reasonable Price.you will get a work friendly Envirment

    ReplyDelete
  21. If you are looking for car battery shop in Gurgaon? look no further, Manishbattery is the best option for you. Manishbattery provide a variety of car batteries in gurugram at affordable cost.

    ReplyDelete
  22. Do you want to know about the ACCA Exam Fees or any details regarding this certification like where you can get ACCA Online courses Study material, and the Semester Fees of this particular certification?

    ReplyDelete
  23. The COSO Framework stands for the Committee of Sponsoring Organizations of the Treadway Commission. It is a framework that organizations can use to manage enterprise risk. If you want to know more about the History, components, and Principals of the COSO Framework read this blog now.

    ReplyDelete
  24. Do you know which institute is best for civil services preparation? ACSA is the reputed and very famous Institute for Civil Services Coaching in Jaipur.

    ReplyDelete
  25. Are you looking for a Ayurvedic massage for your weight loss woes? We have the perfect solution for you! Our ayurvedic massage therapy is a holistic technique that helps balance your body, mind and soul.

    ReplyDelete
  26. ACE Heart Institute Leads work that has raised standards for cardiovascular treatment Best Heart Hospital in Mohali. ACE heart hospital provides the best treatment and believes in the most outstanding service and facilities at an affordable price.

    ReplyDelete
  27. Swings is the Best playschool in Gurgaon. Thanks to its focus on the overall development of children. From speaking and writing to creativity and learning, no aspect of a child’s development is neglected here

    ReplyDelete
  28. Do you want to learn about ACCA Eligibility , Duration, Registration, Fees .This course is designed in such a way that it will help you learn the fundamentals of accounting and finance to a level where you will be able to move on to more advanced courses. The course is divided into two parts: the first part focuses on accounting and financial reporting,

    ReplyDelete
  29. This comment has been removed by the author.

    ReplyDelete
  30. ACE Heart & Vascular Institute is a Best Heart Hospital in Mohali . It holds a strong position of leadership in the nation for all cardiac treatments, ACE heart hospital can provide the best treatment. We believe in offering the most outstanding service and facilities at an affordable price

    ReplyDelete
  31. The 3M 5413 polyimide film tape has exceptional thermal stability and it can retain its original shape and size after being under pressure, twisted, and turned for so long. It is made out of polymer-based imide monomers

    ReplyDelete
  32. This comment has been removed by the author.

    ReplyDelete
  33. The soft construction of 3m double-sided tissue tape 91091 makes this product ideal for many joining, mounting, and sealing applications involving irregular surfaces. Application ideas include attaching trims, labels, lining, fabric, fabric, and web splicing.

    ReplyDelete
  34. This one is the best stylish budget hotel available in Gurgaon with all ultramodern amenities included and stylish value for your plutocrat. For travelers looking for 5-star hotels in Gurgaon Hotel Haut Monde Gurgaon is one of the best business hotels in Gurgaon well known for its homely feel and hospitality hygienic and budget-friendly. it offers 24/7 room service and very good room service along with free parking and AC rooms.

    ReplyDelete
  35. APIR motion sensor is an electronic sensor that measures infrared light emitted by objects. PIR sensor. These are commonly used in PIR-based motion detectors, security alarms, and automatic lighting applications.

    ReplyDelete
  36. Cockroaches are among the most challenging pests to eradicate because they have incredible survival
    skills and have even been known to last one week without a head. One of the greatest treatments
    for cockroach control services, is
    offered by Godrej Pest Control in Gurgaon and is based on the gel formulation, which has been tried and tested by professionals.

    ReplyDelete
  37. We take pleasure in our dedication to provide children the best possible care and education, making Sswingspreschool is the most reliable learning partner and daycare in Gurgaon. We encourage kids to explore, create, and dream in order to develop their foundations and get them ready for the future. We do this by putting extensive safety procedures and protocols in place, as well as a carefully prepared curriculum.

    ReplyDelete
  38. You can buy best learning toys for 3 year old kids. JoGenii will be a great place to find different toys and we offers the most affordable prices for educational toys. These types of wonderful toys are available as jigsaw puzzles, wooden puzzles, cubes, and brain teasers. Jigsaw puzzles and wooden puzzles are great to help learn about colours and shapes.

    ReplyDelete
  39. The best car ac repair in Gurgaonis
    provided by Vishwakarma Automobiles.We offer high-quality,reasonably cost-effective AC services and promised excellent outcomes that are backed by a warranty.

    ReplyDelete
  40. Looking for a 4 star hotel in Gurgaon? look no further than the Haut Monde Hotel.The hotel also offers a wide range of amenities for business travellers, including function rooms, boardrooms, and even a business centre. Plus, you'll have access to free Wi-Fi and high-speed internet throughout the hotel.
    All of these features make the Haut Monde Hotel the perfect place to stay during your visit to Gurgaon.

    ReplyDelete
  41. The most cutting-edge and trustworthy supplier of commercial kitchen equipment manufacturers in Delhi is NRSKitchen, which serves both residential and business clients. There are several goods available from this firm. With their dedication to quality and innovation, they make sure to offer clients the greatest items.

    ReplyDelete
  42. Gurgaon has plenty to offer in terms of auto repair. Highly equipped workshops at Vishwakarma Automobiles provide you the greatest services, excellent quality, best prices, and genuine spare parts for routine maintenance.
    The best car service in Gurgaon have the knowledge and tools necessary to do the task swiftly and correctly. Phone now.

    ReplyDelete
  43. If you are looking for the best cardiologist in Mohali With a team of highly qualified and experienced professionals, ACEheartinstitute is the premier cardiology clinic in Mohali, you can feel the warm and friendly atmosphere and the staff’s commitment to providing the highest quality of care. Their futuristic facility is equipped with the latest technology to ensure that their patients receive the best care possible. .They offer the highest quality of care, so you can rest assured that you are in good.

    ReplyDelete
  44. Floral Metal Wall Decor By Darteffects Add some life to your walls with our metal wall decor. Our floral metal wall decor will make the perfect addition to any room. With a wide variety of colors and designs, you are sure to find the perfect wall decor for your home.

    ReplyDelete
  45. want to know about a company registration fees in Delhi or you want to Create your own company in Delhi at a fraction of the price. Get up and running quickly with the most professional, reliable, and affordable company registration service SRV Associates contact us Today.

    ReplyDelete
  46. If you are looking for the best Panchakarma in Kalyan West. Dirghayuh Treatment Centre is specialty in Panchakarma Treatment. We offer budget effective preventative and healing therapies along with various methods of detoxification and rejuvenation. Contact us for more information.

    ReplyDelete

  47. Best courses for Diploma in IFRS, Our special IFRS training arrives at a much lower cost than standard providers and proposes the flexibility to handle your study objectives, job, and life.

    ReplyDelete

  48. Get the most bang for your buck withRefurbished Macbooks in India! We offer certified pre-owned Apple Macbooks at unbeatable prices and features.

    ReplyDelete
  49. There are many of bakery equipment manufacturers in Delhi. NRSKitchen is a well known and specialized bakery equipment dealer in Delhi serving commercial bakeries, consumers, and bakery organizations.
    We can provide you with the perfect perspective and persona to make your storytelling more enjoyable and interesting.

    ReplyDelete
  50. Soapbox Studios is the best photographer in Gurgaon. We specialize in wedding, family, and commercial photography. Our team is dedicated to providing you with excellent service and quality images.we offer a variety of services that will help make your photo experience unforgettable .

    ReplyDelete
  51. Best Preschool in Gurgaon and Activity Centre is one of the leading preschools in Gurgaon, builds a strong foundation for children’s future. We offers holistic education that meets international standards, it has a friendly, fun, warm, safe nurturing and stress-free environment.

    ReplyDelete
  52. NRSKitchen is one of the premier Bakery Equipment Manufacturer . The company has been providing top-notch bakery equipment for many years, boasting an excellent track record in terms of quality and efficiency. NRSKitchen has a wide range of products to choose from.

    ReplyDelete
  53. Leading the sustainability movement, Eduyush provides ESG certification to businesses looking to have a beneficial influence on the environment, society, and government. Our thorough certification programme assesses a company's performance and practises in crucial areas including ethical governance, reducing carbon footprints, and employee wellbeing.

    ReplyDelete
  54. I really appreciate this wonderful post that you have provided for us. You can visit my website Link. Zonder gas wonen in netherlands

    ReplyDelete