txt file and matlab??? help
Afficher commentaires plus anciens
okay so i have to use a function that i created to change a list of numbers in the text file. the list of numbers are pound and inchs and i have to convert them to cm and kg, however every time i use the function program it changes the whole list into centimetre instead of changing it into centimetre and kilogram. any help would be great. so my function is :
function[centimeter,kilogram]=IPtoCK(inch,pound)
for k=1:44;
if k<=77.4
centimeter=(inch.*2.54);
else
kilogram=(pound.*0.4536);
end
end
end
Réponse acceptée
Plus de réponses (1)
Look at this piece of code:
for k=1:44
if k <= 77.4
...
k goes from 1 to 44. Then k is smaller equal 77.4 in every case.
In addition it is not clear, why you use a loop at all, because the contents of the loop does not depend on the loop counter. I guess this would help:
function [centimeter,kilogram]=IPtoCK(inch,pound)
centimeter = inch .* 2.54;
kilogram = pound .* 0.4536;
2 commentaires
dena hosseini
le 5 Avr 2015
Modifié(e) : Image Analyst
le 5 Avr 2015
Image Analyst
le 5 Avr 2015
It requires two arguments, not one. You passed in only one, called v. You need to extract inch and pound. Maybe like this, depending on what v is:
inches = v.inch;
pounds = v.pound;
[cm, kg] = IPtoCK(inches, pounds);
fid=fopen('convert.txt', 'wt');
fprintf(fid,'%.3f %.3f\n', cm, kg);
fclose(fid);
Catégories
En savoir plus sur Functions dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!