I know this must be a very basic question, but I could not find any answers. I need to create a function that: 1) imports data from an Excel Spreadsheet, 2) assign specific information from this xlsx file to variables and 3) plot this variables.
I wrote the function like this:
crindv[a_] := ({dados = Import[a]};{crpluscond= a[[1, Range[1,19], 2]], crminuscond = a[[1, Range[1,19], 3]]}; ListLinePlot[{crpluscond, crminuscond}, PlotMarkers->{}, PlotLegends->{"CS+", "CS-"}, FrameLabel->{"Condicionamento", "SCR (em \[Mu]S)"},Frame -> {True, True, False, False}, PlotRange->{{0,20}, {0, 1.5}}, FrameTicks-> {False, True}])
When I call this function,
In[36]:= crindv["/Users/pedrofonsecazuccolo/Dropbox/Doutorado/Piloto2/planejamento_e_analise/dados_para_mathematica/camila_mat.xlsx"]
the following error appears and Mathematica produces an empty graph:
During evaluation of In[36]:= Part::partd: Part specification /Users/pedrofonsecazuccolo/Dropbox/Doutorado/Piloto2/planejamento_e_analise/dados_para_mathematica/camila_mat.xlsx[[1,{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},2]] is longer than depth of object. >>
During evaluation of In[36]:= Part::partd: Part specification /Users/pedrofonsecazuccolo/Dropbox/Doutorado/Piloto2/planejamento_e_analise/dados_para_mathematica/camila_mat.xlsx[[1,{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},3]] is longer than depth of object. >>
I don't understand what is going wrong, since I am able to plot the same data by tipping the commands separately, like this:
In[27]:= dados = Import["/Users/pedrofonsecazuccolo/Dropbox/Doutorado/Piloto2/planejamento_e_analise/dados_para_mathematica/camila_mat.xlsx"];
In[28]:= Dimensions[dados]
Out[28]= {1,19,16}
In[32]:= crpluscond = dados[[1, Range[1,19],2]];
crminuscond = dados[[1, Range[1,19],3]];
In[34]:= ListLinePlot[{crpluscond, crminuscond}, PlotMarkers->{}, PlotLegends->{"CS+", "CS-"}, FrameLabel->{"Condicionamento", "SCR (em \[Mu]S)"},Frame -> {True, True, False, False}, PlotRange->{{0,20}, {0, 1.5}}, FrameTicks-> {False, True}];
Why does Mathematica not recognize the same dimensions of the data when it is imported using my function?
Thanks