Clear Filters
Clear Filters

matlab stores the value in ans instead of the variable I assigned

2 views (last 30 days)
I wrote the following function so that I can use the structure 'stormdata' into another function. But matlab is assigning my data into ans instead of stormdata. What is going on here??
function stormdata = readstormdata(mystormdata)
load mystormdata.dat,
[rows, cols] = size(mystormdata);
for i = 1:rows
stormdata(i) = struct('location',mystormdata(i,1),'inches',...
mystormdata(i,2),'hours',mystormdata(i,3),'intensity',...
mystormdata(i,2)/mystormdata(i,3));)/mystormdata(i,3);
end
end

Answers (2)

Jan
Jan on 8 Mar 2015
The question is not clear: Where in the posted code does the variable "ans" appear?
How do you call your function? Like this:
stormdata = readstormdata(mystormdata)
Then it looks strange, that "mystormdata" is the input variable and the name of the .dat file. It is smarter to catch the output of load in a variable, because e.g. the readers in the forum cannot guess, what is written magically to the worksapce by this load.

Nabin SUNAM
Nabin SUNAM on 8 Mar 2015
Sorry the first line is actually,
function stormdata = readstormdata
I want to capture the result of readstormdata into stormdata

Categories

Find more on Graphics Object Identification 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!