Need help to create matlab script to convert currency

Dear all,
I need help to write a matlab script to convert and calculate for the currency below. I can't figure out how to write it. Thanks so much in advance!
Convert from SGD to USD GBP EURO from SGD 1 to 25

Réponses (2)

Here is function for it : you can easily convert to a script if you want.
function currencyTable = convertCurrency(toUsd, toGBP, toEuro)
SGD = (1:25)';
USD = SGD.*toUsd;
GBP = SGD.*toGBP;
EURO = SGD.*toEuro;
currencyTable = table(SGD, USD, GBP, EURO);
% disp(currencyTable);
end
Then call it from the command prompt or another script:
>> currencyTable = convertCurrency(0.74, 0.48, 0.68)

13 commentaires

KSK
KSK le 27 Mai 2015
Nobel Mondal thank you for your reply. but the display have to be like below image and the result have to be from 1SGD to 25 SGD to equivalent to the rest of the currency.
Well, on my end it looks the same which you have mentioned. Can you please show me the output you're getting?
If you are expecting the results to come out in blue, then you are going to have a difficult time.
If you are not expecting the result to come out in blue, then their solution looks pretty good; it comes out like
SGD USD GBP EURO
___ _____ _____ _____
1 0.74 0.48 0.68
2 1.48 0.96 1.36
3 2.22 1.44 2.04
4 2.96 1.92 2.72
5 3.7 2.4 3.4
6 4.44 2.88 4.08
7 5.18 3.36 4.76
8 5.92 3.84 5.44
9 6.66 4.32 6.12
10 7.4 4.8 6.8
11 8.14 5.28 7.48
12 8.88 5.76 8.16
13 9.62 6.24 8.84
14 10.36 6.72 9.52
15 11.1 7.2 10.2
16 11.84 7.68 10.88
17 12.58 8.16 11.56
18 13.32 8.64 12.24
19 14.06 9.12 12.92
20 14.8 9.6 13.6
21 15.54 10.08 14.28
22 16.28 10.56 14.96
23 17.02 11.04 15.64
24 17.76 11.52 16.32
25 18.5 12 17
KSK
KSK le 27 Mai 2015
Modifié(e) : KSK le 27 Mai 2015
Hi Nobel, Thank you for your help! below is the error i am facing.
Undefined function or variable 'toUsd'
You are attempting to run the code by using the menu Run function, or pressing F5. You cannot do that for functions. Instead you need to follow what he said,
Then call it from the command prompt or another script:
>> currencyTable = convertCurrency(0.74, 0.48, 0.68)
Nobel Mondal
Nobel Mondal le 27 Mai 2015
Modifié(e) : Nobel Mondal le 27 Mai 2015
If you're still facing the problem, just use this script ( in stead of the function)
toUsd = 0.74; toGBP = 0.48; toEuro 0.68;
SGD = (1:25)';
USD = SGD.*toUsd;
GBP = SGD.*toGBP;
EURO = SGD.*toEuro;
currencyTable = table(SGD, USD, GBP, EURO);
disp(currencyTable)
still can't. it still giving me the below error.
>> currency conversion(toUsd, toGBP, toEuro)
Undefined function 'currency' for input arguments of type 'char'.
You cannot name a function with a space. Your .m file name must not have any spaces in it. The first character must be a letter, and the characters after that must be a letter, or a digit, or the underscore ('_'). The permitted letters are ones of the English (Latin) alphabet, uppercase or lowercase.
Permitted function names are explained here:
thanks walter, now i am getting the error below. i don't why i can't display out the table like you show on the above.
Error in currency1 (line 6)
currencyTable = table(SGD, USD, GBP, EURO);
You do not show us what the error is. Is it possibly saying that there is no such function or variable "table" ?
If you're using older than R2013b version of Matlab, it might not support table datatype.
KSK
KSK le 28 Mai 2015
Modifié(e) : KSK le 28 Mai 2015
Sorry guys i am using the version R2013a. Below is the error after i click run from the script.

Connectez-vous pour commenter.

Suganthi D
Suganthi D le 15 Mar 2022

0 votes

how to convert USD value to INR ...pls help me ..i have attached my code here.. These are the USD values 0.0548 , 0.1050,0.1541,0.1050.... IS this correct way to write the currency conversion..
function currencyTable = convertCurrency(toINR)
currencyTable = convertCurrency(0.0548, 0.1050, 0.1541, 0.1050);
INR = USD.*toINR;
currencyTable = table( INR);
disp(currencyTable);
end

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Question posée :

KSK
le 27 Mai 2015

Community Treasure Hunt

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

Start Hunting!

Translated by