How to paste text to function
Show older comments
Hi all,
I have this file mat.txt with cell array format:
year,month,day,hour,hst,doy,TempAvg,TempLow,TempHigh,HumAvg,HumLow,HumHigh,BaroAvg,BaroLow,BaroHigh,Windspeed,Gust,WindDirection,IntervalPrecip,SolarRadiationAvg,InsideTempAvg,InsideTempLow,InsideTempHigh,HeatIndex,WindChill,DewPoint,StationVoltage,wetbulb
I want to put the text above to the in the fucntion:
function textread(file)
[year,month,day,hour,hst,doy,TempAvg,TempLow,TempHigh,HumAvg,HumLow,HumHigh,BaroAvg,BaroLow,BaroHigh,Windspeed,Gust,WindDirection,IntervalPrecip,SolarRadiationAvg,InsideTempAvg,InsideTempLow,InsideTempHigh,HeatIndex,WindChill,DewPoint,StationVoltage,wetbulb] =...
textread(file,'%f %f %f %s %f %f %f %f %f %f %f %f %f %f %f %f %f','delimiter',',');
Can you help me to write code to copy text in txt file and paste it in the textread fuction?
I tried to use fprintf, textscan but it doesn't work with mix text like this
Thank you so much
4 Comments
Walter Roberson
on 8 Feb 2020
Temp Avg is not a valid variable name.
If yu did manage to inject those variables into your function, then you would have the difficulty that the values would be stuck inside the function, since you do not return anything.
quynh tran
on 8 Feb 2020
Naming your function textread is unlikely to work very well when inside that function you call a function named textread. Or is it your intention to write a recursive function with no stopping condition?
Nearly obsolete textread has this warning at the top of its documentation:
"I have alot of files with different variables so I don't want to take time to copy and paste it. This seems useless but I can save a lot of time and run it in program without opening the files"
This is entirely the wrong approach. You would be much better of using readtable or learning how to store/pass parameters in structures. The approach you have invented for yourself is an inefficient dead-end.
quynh tran
on 10 Feb 2020
Accepted Answer
More Answers (0)
Categories
Find more on Language Support 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!