Upload
rahuldbajaj2011
View
218
Download
0
Embed Size (px)
Citation preview
7/28/2019 How to Save, For Loop - MATLAB Answers - MATLAB Central
1/3
Search: Answers
Rahul Bajaj Create Community Profile Log Out
File Exchange Answ ers Newsgroup Link Exchange Blogs Trendy Cody Contest MathWorks.com
Include the reason for your flag below : Your message w ill be publicly visible.
Include the reason for your flag below : Your message w ill be publicly visible.
Not appropriate for MATLAB Answ ers
Spam
Unclear
Provide additional information about your flag below Your message w ill be publicly v isible.
How to save, for loop
Asked by Hello kity on 14 Dec 2012
Latest activityCommented on by Hello kity on 14 Dec 2012Accepted Answ erby Pedro Villena
Example:
for i=1:n X=DATA1(i,1); Y=DATA2{1,i}; Z=X-Y;
end
what I want is that it saves the data to Z, summing them, so , for i=1 , Z=[1 2 3 4 5], for i=2 Z becomes Z=[1 2 3 4 5 6 7] etc.
so i need to do s omething w ith Z but dont know what. currently it only shows the res ult of the last i.
2 Comments
Show all comments
Image Analyst on 14 Dec 2012
Link
Direct link to this comment:
http://www.mathworks.in/matlabcentral/answers/56588#comment_117220
Flag
Save Cancel
Do you really have X as a numerical array (double, etc.) and Y as a cell array???
Hello kity on 14 Dec 2012
Link
Direct link to this comment:
http://www.mathworks.in/matlabcentral/answers/56588#comment_117226
Flag
Save Cancel
yes x= column full of values (num merical array) and Y cells , with each cell with diff lengths
0 votes
Flag
A flag is a request to an ed itor to review and potentia lly close or delete con tent on MATLAB Answers. Include the reason for your flag
below.
More
Inappropriate flags an invalid ques tion. These questions lack any of the following:
Detail for ensuring a proper response
Sufficient work or thought on the part of the reques ter (do-it-for-me request)
Usefulness to the community
More
This question is spam.
More
Unclear flags a question requiring more information. These questions are illogical, lack detail, or may not be a question.
Unclear questions can be reopened within 10 days of closure. Thereafter, unclear questions become perm anently deleted.
http://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loophttp://www.mathworks.in/matlabcentral/answers/contributors/3915892-hello-kityhttp://www.mathworks.in/matlabcentral/answers/flagged/new?flaggable_id=117226&flaggable_type=Commenthttp://www.mathworks.in/matlabcentral/answers/flagged/new?flaggable_id=117226&flaggable_type=Commenthttp://www.mathworks.in/matlabcentral/answers/56588#comment_117226http://www.mathworks.in/matlabcentral/answers/56588#comment_117226http://www.mathworks.in/matlabcentral/answers/contributors/3915892-hello-kityhttp://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loop#toggle-commentshttp://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loop#answer_68515http://www.mathworks.in/matlabcentral/answers/56588#comment_117226http://www.mathworks.in/matlabcentral/answers/contributors/1072042-pedro-villenahttp://www.mathworks.in/matlabcentral/answers/contributors/3915892-hello-kityhttp://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loophttp://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loophttp://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loophttp://www.mathworks.in/matlabcentral/answers/flagged/new?flaggable_id=56588&flaggable_type=Questionhttp://www.mathworks.in/matlabcentral/answers/contributors/3915892-hello-kityhttp://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loophttp://www.mathworks.in/matlabcentral/answers/flagged/new?flaggable_id=117226&flaggable_type=Commenthttp://www.mathworks.in/matlabcentral/answers/56588#comment_117226http://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loop#comment_117226http://www.mathworks.in/matlabcentral/answers/contributors/3915892-hello-kityhttp://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loophttp://www.mathworks.in/matlabcentral/answers/flagged/new?flaggable_id=117220&flaggable_type=Commenthttp://www.mathworks.in/matlabcentral/answers/56588#comment_117220http://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loop#comment_117220http://www.mathworks.in/matlabcentral/answers/contributors/1343420-image-analysthttp://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loop#toggle-commentshttp://www.mathworks.in/matlabcentral/answers/contributors/1072042-pedro-villenahttp://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loop#answer_68515http://www.mathworks.in/matlabcentral/answers/contributors/3915892-hello-kityhttp://www.mathworks.in/matlabcentral/answers/56588#comment_117226http://www.mathworks.in/matlabcentral/answers/contributors/3915892-hello-kityhttp://www.mathworks.in/http://www.mathworks.in/matlabcentral/contest/http://www.mathworks.in/matlabcentral/codyhttp://www.mathworks.in/matlabcentral/trendyhttp://blogs.mathworks.com/http://www.mathworks.in/matlabcentral/linkexchange/http://www.mathworks.in/matlabcentral/newsreader/http://www.mathworks.in/matlabcentral/answers/http://www.mathworks.in/matlabcentral/fileexchange/https://www.mathworks.in/accesslogin/logout.do?uri=http%3A%2F%2Fwww.mathworks.in%2Fmatlabcentral%2Fanswers%2F56588-how-to-save-for-loophttps://www.mathworks.in/accesslogin/editCommunityProfile.do?uri=http%3A%2F%2Fwww.mathworks.in%2Fmatlabcentral%2Fanswers%2F56588-how-to-save-for-loophttp://www.mathworks.in/matlabcentral/7/28/2019 How to Save, For Loop - MATLAB Answers - MATLAB Central
2/3
Include the reason for your flag below : Your message w ill be publicly visible.
Include the reason for your flag below : Your message w ill be publicly visible.
Save Cancel
Tags
cell2mat
Products
MATLAB
1 Answer
Answ er by Pedro Villena on 14 Dec 2012Edited by Pedro Villena on 14 Dec 2012
Accepted answ er
for i=1:n,
X = DATA1(i,1); %% DATA1 is an array
Y = DATA2{i,1}; %% DATA2 is a cell
Z(i,:) = X-Y;
end
save Z
or
Z = DATA1 + cell2mat(DATA2);
save Z
1 Comment
Show all comments
Hello kity on 14 Dec 2012
Link
Direct link to this comment:
http://www.mathworks.in/matlabcentral/answers/56588#comment_117214
Flag
Save Cancel
the first one works if both X and Y are matrix ( ()) but if Y is cell array {} then it gives trouble. Somehow I need to convert Y to ma trix then
put it in the equation.
I look into the second tip
thank you
0 votes
Flag
Save Cancel
Link
Direct link to this answer:
http://www.mathworks.in/matlabcentral/answers/56588#answer_68515
Create a comm unity profile to answer or comment on this question.
Contact us
http://www.mathworks.in/company/feedback/https://www.mathworks.in/accesslogin/editCommunityProfile.do?uri=http%3A%2F%2Fwww.mathworks.in%2Fmatlabcentral%2Fanswers%2F56588-how-to-save-for-loophttp://www.mathworks.in/matlabcentral/answers/56588#answer_68515http://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loop#answer_68515http://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loophttp://www.mathworks.in/matlabcentral/answers/flagged/new?flaggable_id=68515&flaggable_type=Answerhttp://www.mathworks.in/matlabcentral/answers/contributors/1072042-pedro-villenahttp://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loophttp://www.mathworks.in/matlabcentral/answers/flagged/new?flaggable_id=117214&flaggable_type=Commenthttp://www.mathworks.in/matlabcentral/answers/56588#comment_117214http://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loop#comment_117214http://www.mathworks.in/matlabcentral/answers/contributors/3915892-hello-kityhttp://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loop#toggle-commentshttp://www.mathworks.in/matlabcentral/answers/contributors/1072042-pedro-villenahttp://www.mathworks.in/matlabcentral/answers/contributors/1072042-pedro-villenahttp://www.mathworks.in/matlabcentral/answers/?term=product%3A%22MATLAB%22http://www.mathworks.in/matlabcentral/answers/?term=tag%3A%22cell2mat%22http://www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loop7/28/2019 How to Save, For Loop - MATLAB Answers - MATLAB Central
3/3
Site Help Patents Trademarks Privacy Policy Preventing Piracy Terms of Use
Featured MathWorks.com Topics: New Products Support Documentat ion Train ing Webinars Newsletters MATLAB Tria ls Careers
1994-2013 T he M athWorks, Inc.
http://www.mathworks.in/company/jobs/opportunities/index_en_US.htmlhttp://www.mathworks.in/programs/trials/trial_request.html?prodcode=ML&s_cid=MLC_trialshttp://www.mathworks.in/company/newsletters/http://www.mathworks.in/company/events/webinars/http://www.mathworks.in/services/training/http://www.mathworks.in/helphttp://www.mathworks.in/support/http://www.mathworks.in/products/new_products/latest_features.htmlhttp://www.mathworks.in/matlabcentral/termsofuse.htmlhttp://www.mathworks.in/company/aboutus/policies_statements/piracy.htmlhttp://www.mathworks.in/company/aboutus/policies_statements/http://www.mathworks.in/company/aboutus/policies_statements/trademarks.htmlhttp://www.mathworks.in/company/aboutus/policies_statements/patents.htmlhttp://www.mathworks.in/help.htmlhttp://www.mathworks.in/programs/bounce_hub_generic.html?s_cid=mlc_twt&url=http://www.twitter.com/MATLABhttp://www.mathworks.in/programs/bounce_hub_generic.html?s_cid=mlc_fbk&url=http://www.facebook.com/MATLABhttp://www.mathworks.in/programs/bounce_hub_generic.html?s_cid=mlc_fbk&url=https://plus.google.com/117177960465154322866?prsrc=3http://www.mathworks.in/company/rss/