Publish Problem in PDF

Hello.
I have tried to publish my work, but I just get out in the output just a small part of my work. No figures is not either displayed in the output.
Why can't I publish all my code? I have tried for hours to figures this out, but now I feel I need your help on MATLAB Central.
I want to publish my work in pdf.
Please, help me. What am I doing wrong here?
Kind regards Cillian

4 Comments

per isakson
per isakson on 31 Aug 2012
Edited: per isakson on 31 Aug 2012
Could you show a code-snippet that illustrates the problem? Something that we could use to try to reproduce the behavior you describe.
My impression is that
  1. publish works as it should
  2. some details of the documentation are easy to miss
  3. the output to pdf doesn't look as nice as does the html-output
Which versions of Matlab and OS do you use?
It works when I take one cell one by one, the figures appears then.
Here is a code-snippet, (sorry, I couldn't do it shorter).
% Method 1
function [t,U]=forwardEuler(f,I,U0,N)
t=linspace(I(1),I(2),N+1);
U=zeros(length(U0),size(t,2));
U(:,1)=U0;
k=t(2)-t(1);
for n=2:N+1
U(:,n)=U(:,n-1) + k*f(t(n-1),U(:,n-1));
end
U=U';
t=t';
end
% Method 2
function [t,U]=backwardEuler(f,I,U0,N)
t=linspace(I(1),I(2),N+1);
U=zeros(length(U0),size(t,2));
U(:,1)=U0;
k=t(2)-t(1);
tol=k^2;
for n=2:N+1
U(:,n)=U(:,n-1);
U_old=U(:,n)+2*tol;
while norm(U(:,n)-U_old)>tol
U_old=U(:,n);
U(:,n)=U(:,n-1)+k*f(t(n),U(:,n));
end
end
U=U';
t=t';
% Method 3
function [t,U]=mittpunkten(f,I,U0,N)
t=linspace(I(1),I(2),N+1);
U=zeros(length(U0),size(t,2));
U(:,1)=U0;
k=t(2)-t(1);
tol=k^2;
for n=2:N+1
U(:,n)=U(:,n-1);
U_old=U(:,n)+2*tol;
while norm(U(:,n)-U_old)>tol
U_old=U(:,n);
U(:,n)=U(:,n-1)+k*f(((t(n) + t(n-1))/2),(U(:,n) + U(:,n-1)/2));
end
end
U=U';
t=t';
I use version R2011b (7.13.0.564), and I have Mac OS X, Snow leopard. (10.6.8).
Is there limits in Matlab how much code you can put between cellbreaks? Because I tried to publish just a cellbreak, and just half of the code is displayed.
The code you provide includes three independent functions. I created three m-files. None of the three outputs anything to the screen.
How am I supposed to use these functions?
I know there is no output, but I am supposed to create just one m.file consisting of these three functions.
I am looking for the code to be displayed in the output. For some reason, the code is not displayed.

Sign in to comment.

 Accepted Answer

per isakson
per isakson on 1 Sep 2012
Edited: per isakson on 1 Sep 2012
You have provided three main functions
  1. forwardEuler
  2. backwardEuler
  3. mittpunkten
which you want to publish to one file.
You say "For some reason, the code is not displayed.", but you don't tell what you do to publish the functions and you do not say exactly what you expect. Thus, you rely on us guessing.
You say "No figures is not either displayed in the output.", which made me believe that you expected some kind of Matlab figure in the output. What did you try to communicate with this sentence?
AFAIK: It is not possible to publish three main functions to one document. You can, however, publish to three and merge to one.
I have created three m-files, one of which contains
% Method 1
function [t,U]=forwardEuler(f,I,U0,N)
if nargin == 0
return
end
t=linspace(I(1),I(2),N+1);
U=zeros(length(U0),size(t,2));
U(:,1)=U0;
k=t(2)-t(1);
for n=2:N+1
U(:,n)=U(:,n-1) + k*f(t(n-1),U(:,n-1));
end
U=U';
t=t';
end
.
My tests (R2012a):
>> publish('forwardEuler')
ans =
h:\m\cssm\html\forwardEuler.html
this html-file contains a grey box with the code as I expect.
>> publish('forwardEuler','pdf')
ans =
h:\m\cssm\html\forwardEuler.pdf
the pdf-file looks ok to me.
Clicking the button, "Publish forwardEuler.m", in the toolbar creates an identical html-file and opens it in the Matlab browser.

7 Comments

Cillian
Cillian on 2 Sep 2012
Edited: Cillian on 2 Sep 2012
Sorry, I haven't been so clear what I meant here. All I want it's to view/show how the code looks like for forwardEuler,backwardEuler and mittpunkten. There is no need for output. Nevermind about the figures.
I tried with your suggestion, I put these code into one cell;
Eulers Framåtmetod publish('forwardEuler','pdf')
Eulers Bakåtlösare publish('backwardEuler','pdf')
Mittpunktsmetoden publish('mittpunkten','pdf')
But it seems not working for me. When I publish my work, nothing i is happening.
Jag tror att någonstans på din hårddisk finns en katalog, som antagligen heter "html" och i denna finns filerna
  • forwardEuler.pdf
  • backwardEuler.pdf
  • mittpunkten.pdf
Prova följande i kommandofönstret
msg = publish('forwardEuler','pdf')
Det är inte likt Matlab att ingenting händer. Jag förstår fortfarande inte exakt vad du gör. Det påminner mig om nybörjaren, som skriver in kommandot men inte avslutar med Enter-tangenten eftersom det inte står i anvisningen.
Ja, det stämmer.
Men du har nog missförstått mig igen, det är kanske bättre att vi tar detta på svenska. Så här är det: det enda jag vill är att publicera hela mitt arbete till en html/pdf-fil. Men av någon anledning syns varken kod eller figurer, (endast en liten del av koden syns, vilket är forwardEuler och backwardEuler, inget mer).
Koden som jag har visat dig hittills, är bara ett litet avsnitt av den totala koden.
Detta syns i html-fil formatet:
Contents
2.1 Färdigställ lösare
% Eulers Framåtmetod
function [t,U]=forwardEuler(f,I,U0,N) % "forwardEuler" är namnet
t=linspace(I(1),I(2),N+1); %Genererar tidsnoder
U=zeros(length(U0),size(t,2)); %Vektor där lösningen sparas
U(:,1)=U0; %Första värdet är begynnelsevärdet
k=t(2)-t(1); %Steglängden
for n=2:N+1
U(:,n)=U(:,n-1) + k*f(t(n-1),U(:,n-1)); %
end
U=U'; %Vi gör om till radvektorer
t=t'; %för att göra lika som ode45
end
Eulers Bakåtlösare
function [t,U]=backwardEuler(f,I,U0,N)
t=linspace(I(1),I(2),N+1); %Genererar tidsnoder
U=zeros(length(U0),size(t,2)); %Vektor där lösningen sparas
U(:,1)=U0; %Första värdet är begynnelsevärdet
k=t(2)-t(1); %Steglängden
tol=k^2; %Fixpunktstolerans
for n=2:N+1
U(:,n)=U(:,n-1); %Vi sätter en första gissning på U(:,n) till
%till värdet innan.
U_old=U(:,n)+2*tol; %U_old sätts så att while-loopen påbörjas.
while norm(U(:,n)-U_old)>tol %Om U(:,n) är längre ifrån vad det
%var förra varvet så uppdaterar vi.
U_old=U(:,n); %Vi spar värdet som U(:,n) har för att kunna jäamföra.
U(:,n)=U(:,n-1)+k*f(t(n),U(:,n)); %Fixpunktssteg. Ändra här för
%att få mittpunktsmetoden!
end
Som man nu ser, så syns inte mittpunkten, konstigt. Jag förstår inte heller varför resten av min inte kod syns. Det saknas uppgift 2.2 - 2.8, samt figurer.
Hoppas att detta var mer förtydligande.
Hälsningar Cillian
Hej Cillian
Jag vet inte vad jag ska säga. Jag har fortfarande ingen klar bild av funktionen/skriptet, som du försöker publicera.
  1. Hur mycket har du använt publish tidigare? Kan det vara så att du försöker göra något som publish inte stödjer. Matlabs dokumentation är ofta svår att tolka vad beträffar funktioners begränsningar.
  2. Visar Matlab verkligen inte ett litet felmeddelande på skärmen eller i pdf-filen?
  3. Det förbryllar mig att strängen "% Eulers Framåtmetod" men inte "Eulers Bakåtlösare" inleds av "%" (i din kommentar ovan).
  4. publish's beteende styrs av en massa "optioner". Använder du något annat än default med undantag av pdf? Nedan ser du värdena jag använder (bara default).
  5. Hos The Mathworks använder de publish regelbundet, i boggar m.m. Man borde ha hittat de flesta större buggarna.
  6. När Loren diskuterar kod i sin blogg använder hon ofta kommandot "type funktions_namn"
  7. Det är dags för dig köra enkla exempel utan dina lösare. All kod bara förvillar. Jag kan inte tänka mig att det är där problemet ligger med tanke på att Matlab inte visar ett felmeddelande. Använd t.ex. temat "Hello World!".
Ställ frågan till tech-support - om licensen du använder tillåter det?
K>> options
options =
format: 'html'
evalCode: 1
useNewFigure: 1
showCode: 1
stylesheet: 'C:\...\private\mxdom2simplehtml.xsl'
codeToEvaluate: [1x108 char]
createThumbnail: 1
figureSnapMethod: 'entireGUIWindow'
imageFormat: ''
maxHeight: []
maxWidth: []
stopOnError: 1
catchError: 1
maxOutputLines: Inf
font: ''
titleFont: ''
bodyFont: ''
monospaceFont: ''
Snart kommer vän av ordning och talar om att det är engelska som gäller här.
Lycka till per
Cillian
Cillian on 4 Sep 2012
Edited: Cillian on 4 Sep 2012
Thank you for your advices, Per.
I figured that out and I finally succéed to publishing my work with figures and everything.
Could you outline the solution for others that might encounter this problem?
I haven't a clue what caused or solved the problem and our communication in Swedish doesn't even provide a hint.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!