subplot with multiple images - Pulling images from API into one figure
Ältere Kommentare anzeigen
Hello, I have some working code where I search for chemical structures (compounds) via the PubChem API, and then loop through the retrieved PubChem Compound identifiers and display the PNG images of them. What I would like to do is not create a separate figure for each image, but rather use something like subplot to create a grid (3 columns wide). This way, all of the compound images are in one figure. I am not having much luck. Your help would be much appreciated. Here is the code I wrote below:
% Search for chemical structures by Identity (same connectivity, SC) as Ingenol
api = 'https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/';
SC_url = [api 'fastidentity/cid/442042/cids/JSON?identity_type=same_connectivity'];
SC = webread(SC_url);
SC = num2cell(SC.IdentifierList.CID)
% Retrieve PNG images of same connectivity CIDs in SC dataset.
% loop through CIDs and define web api url
for r = 1:length(SC)
SC_CID = SC{r};
SC_CID_url = [api 'cid/' num2str(SC_CID) '/PNG'];
try
% retrieve CID PNG image and display
[SC_CID_img,map] = imread(SC_CID_url);
figure;
imshow(SC_CID_img,map)
drawnow;
title(num2str(SC_CID));
% be polite to PubChem server
n = 1;
pause(n);
catch
disp('CID image not found')
disp('Execution will continue')
end
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Image Arithmetic finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
