Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Nabin SUNAM
Nabin SUNAM le 8 Mar 2015
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

Réponses (2)

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

Catégories

En savoir plus sur Graphics Object Identification dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by