txt file and matlab??? help
Show older comments
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
Accepted Answer
More Answers (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 Comments
dena hosseini
on 5 Apr 2015
Edited: Image Analyst
on 5 Apr 2015
Image Analyst
on 5 Apr 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);
Categories
Find more on Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!