How to save no variable

4 ビュー (過去 30 日間)
MIHYUN
MIHYUN 2014 年 7 月 14 日
コメント済み: MIHYUN 2014 年 7 月 14 日
This is my code.
Lat = 30;
Lon = 12;
base_url =[ 'http://maps.googleapis.com/maps/api/geocode/json'];
formatSpec = '%4.6f';
LatLon = [num2str(Lat,formatSpec),',',num2str(Lon,formatSpec)];
request_url = [base_url '?latlng=' LatLon '&sensor=true_or_false']
docNode = urlread(request_url);
data = json.load(docNode);
n = size(data.results,2);
i = 1;
for i = 1:n
a = data.results(1,i).types(1,1);
b = data.results(1,i).formatted_address;
if strcmp(a,'country') == 1
sprintf(b)
else if strcmp(a,'locality') == 1
c = b;
sprintf(c)
end
end
end
save('name.mat','b','c')
name = load('name.mat','-mat');
N = struct2cell(name);
When you run the above code , the following message will appear. Variable 'c' not found.
So, I want to save as " no data " when there is no value of c or b as the message. What should I do?

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 7 月 14 日
編集済み: Azzi Abdelmalek 2014 年 7 月 14 日
In your test assign something to your variable c
if strcmp(a,'country')
sprintf(b)
c='no data'
elseif strcmp(a,'locality')
c = b;
sprintf(c)
end
  1 件のコメント
MIHYUN
MIHYUN 2014 年 7 月 14 日
Thank you for helping me. But I have a question.
If error message is ' Variable 'b' not found.', is it same code?
(That is, Whenever change the value of latitude & longitude, It may or may not be exist the value of b and c.
And the value of c does not exist naturally if there is no value of b.)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeJSON Format についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by