Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
function with multiple outputs

Subject: function with multiple outputs

From: Sinduja Rajan Babu

Date: 27 Apr, 2011 13:03:05

Message: 1 of 2

I have a simple script here with some data being imported in from an excel file:

clear all
format long
Airfoils=csvread('trial.csv');
[selected_airfoils]=input('Input airfoil identifiers in 1xn vector format: ')

for i=1:length(selected_airfoils)
    matrix_coords(:,i)=[Airfoils(2:end,selected_airfoils(i))]
end
disp('These are the following combinations possible for different airfoil numbers: ')
disp('Airfoils Combinations')
disp(' 2 1 ')
disp(' 3 3 ')
disp(' 4 6 ')
disp(' 5 10 ')
disp(' 6 15 ')
disp(' 7 21 ')
disp(' 8 28 ')
disp(' 9 36 ')
disp(' 10 45 ')

format long
for jj=1:input('number of combinations: ')
for ii=1:(length(selected_airfoils)-1)
for kk=2:length(selected_airfoils)
    Del=[matrix_coords(1:end,ii)-matrix_coords(1:end,kk)]
end
end
end

And this gives an array for Del which is meant to contain three columns but only returns one, as it overwrites the others. I suppose its a simple coding problem and have tried so many random (:, ) things and cant get it to work. Help!

Subject: function with multiple outputs

From: Florin Neacsu

Date: 27 Apr, 2011 22:50:05

Message: 2 of 2

"Sinduja Rajan Babu" wrote in message <ip9469$in9$1@fred.mathworks.com>...
> I have a simple script here with some data being imported in from an excel file:
>
> clear all
> format long
> Airfoils=csvread('trial.csv');
> [selected_airfoils]=input('Input airfoil identifiers in 1xn vector format: ')
>
> for i=1:length(selected_airfoils)
> matrix_coords(:,i)=[Airfoils(2:end,selected_airfoils(i))]
> end
> disp('These are the following combinations possible for different airfoil numbers: ')
> disp('Airfoils Combinations')
> disp(' 2 1 ')
> disp(' 3 3 ')
> disp(' 4 6 ')
> disp(' 5 10 ')
> disp(' 6 15 ')
> disp(' 7 21 ')
> disp(' 8 28 ')
> disp(' 9 36 ')
> disp(' 10 45 ')
>
> format long
> for jj=1:input('number of combinations: ')
> for ii=1:(length(selected_airfoils)-1)
> for kk=2:length(selected_airfoils)
> Del=[matrix_coords(1:end,ii)-matrix_coords(1:end,kk)]
> end
> end
> end
>
> And this gives an array for Del which is meant to contain three columns but only returns one, as it overwrites the others. I suppose its a simple coding problem and have tried so many random (:, ) things and cant get it to work. Help!

Hi,

On each iteration you are writing something in Del (hence destroying the previous values). So at the end of you for loops you will only have the output of the last iteration.

Regards,
Florin

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us