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

2 次查看(过去 30 天)
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

回答(2 个)

Jan
Jan 2015-3-8
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 2015-3-8
Sorry the first line is actually,
function stormdata = readstormdata
I want to capture the result of readstormdata into stormdata

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by