I worked in institute A as a researcher. Then I started my study as Ph.D student at institute B. The work in institute A was not related to my proposal provided for my Ph.D studies. I sent a paper related to my works in institute A and they publish it. In the acknowledgement part I mentioned my gratitude to institute A and also affilitation to Institute A. I think that I should write my affilitation to institute B? Am I right? If so, is it possible to change my affilitation after publishing?
Your affiliation on the front of the paper should be Institute A where you did the work. However you should also provide a current address for readers who may wish to contact you. So simply add a footnote to the paper (often this can be on the front page) stating that your current address and email is is now at Institute B. Once the paper has been published it cannot be changed.