Matlab function works very slow





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















Extrapolating from a .mat file of the vectors x, y, z I have seen that my code is very slow in the operation and I can not understand why, even though I have done a lot of evidence about it.
The .mat file is initially composed of a 1x1 struct to which I access (in the code is: fileAllData{i,1}), a 2x1 cell to which I access (in the code: (attivita{1,j})) and finally the final cell to which I access ({s,1}).



function[x, y, z, s] = getXYZ(pathData, j, i, s)
fullDataPath = sprintf(...);
fileAllData = importdata(fullDataPath);
m = fileAllData{i,1}.(attivita{1,j}){s,1};

x = m(1,:)';
y = m(2,:)';
z = m(3,:)';
.....
s = s+1;

end


Main function:
.....
for j = 1:K
for i = 1:nSubjects
s = 1;
while s<=trials(j)

[x, y, z, s] = getXYZ(pathData, j, i, s);
end
end
end
...


What can be attributed to slowness? I do not know how to access data more efficiently. What can I try?










share|improve this question


















  • 2





    Have you tried profiling this function? You can do that by setting up a script which calls the function, and pressing "Run and Time" in the top bar. That'll tell you which parts of your function are the most time consuming. Run that, then edit the question to contain the result and investigate from there.

    – Adriaan
    Nov 22 '18 at 14:31











  • Second the suggestion on profiling, also - how much total data is there? Would it make more sense to read the file once and get the data in memory, then process it?

    – paisanco
    Nov 22 '18 at 14:32











  • I solve the problem with the suggestion of Adriaan, thank you very very much

    – Sara Savio
    Nov 22 '18 at 14:46











  • Sara, if you solved the problem, please post an answer here, and accept it. Thanks!

    – Cris Luengo
    Nov 22 '18 at 19:09











  • I bet your problem is in importdata. I’d suggest reading in the data only once, reading data is expensive.

    – Cris Luengo
    Nov 22 '18 at 19:10


















1















Extrapolating from a .mat file of the vectors x, y, z I have seen that my code is very slow in the operation and I can not understand why, even though I have done a lot of evidence about it.
The .mat file is initially composed of a 1x1 struct to which I access (in the code is: fileAllData{i,1}), a 2x1 cell to which I access (in the code: (attivita{1,j})) and finally the final cell to which I access ({s,1}).



function[x, y, z, s] = getXYZ(pathData, j, i, s)
fullDataPath = sprintf(...);
fileAllData = importdata(fullDataPath);
m = fileAllData{i,1}.(attivita{1,j}){s,1};

x = m(1,:)';
y = m(2,:)';
z = m(3,:)';
.....
s = s+1;

end


Main function:
.....
for j = 1:K
for i = 1:nSubjects
s = 1;
while s<=trials(j)

[x, y, z, s] = getXYZ(pathData, j, i, s);
end
end
end
...


What can be attributed to slowness? I do not know how to access data more efficiently. What can I try?










share|improve this question


















  • 2





    Have you tried profiling this function? You can do that by setting up a script which calls the function, and pressing "Run and Time" in the top bar. That'll tell you which parts of your function are the most time consuming. Run that, then edit the question to contain the result and investigate from there.

    – Adriaan
    Nov 22 '18 at 14:31











  • Second the suggestion on profiling, also - how much total data is there? Would it make more sense to read the file once and get the data in memory, then process it?

    – paisanco
    Nov 22 '18 at 14:32











  • I solve the problem with the suggestion of Adriaan, thank you very very much

    – Sara Savio
    Nov 22 '18 at 14:46











  • Sara, if you solved the problem, please post an answer here, and accept it. Thanks!

    – Cris Luengo
    Nov 22 '18 at 19:09











  • I bet your problem is in importdata. I’d suggest reading in the data only once, reading data is expensive.

    – Cris Luengo
    Nov 22 '18 at 19:10














1












1








1








Extrapolating from a .mat file of the vectors x, y, z I have seen that my code is very slow in the operation and I can not understand why, even though I have done a lot of evidence about it.
The .mat file is initially composed of a 1x1 struct to which I access (in the code is: fileAllData{i,1}), a 2x1 cell to which I access (in the code: (attivita{1,j})) and finally the final cell to which I access ({s,1}).



function[x, y, z, s] = getXYZ(pathData, j, i, s)
fullDataPath = sprintf(...);
fileAllData = importdata(fullDataPath);
m = fileAllData{i,1}.(attivita{1,j}){s,1};

x = m(1,:)';
y = m(2,:)';
z = m(3,:)';
.....
s = s+1;

end


Main function:
.....
for j = 1:K
for i = 1:nSubjects
s = 1;
while s<=trials(j)

[x, y, z, s] = getXYZ(pathData, j, i, s);
end
end
end
...


What can be attributed to slowness? I do not know how to access data more efficiently. What can I try?










share|improve this question














Extrapolating from a .mat file of the vectors x, y, z I have seen that my code is very slow in the operation and I can not understand why, even though I have done a lot of evidence about it.
The .mat file is initially composed of a 1x1 struct to which I access (in the code is: fileAllData{i,1}), a 2x1 cell to which I access (in the code: (attivita{1,j})) and finally the final cell to which I access ({s,1}).



function[x, y, z, s] = getXYZ(pathData, j, i, s)
fullDataPath = sprintf(...);
fileAllData = importdata(fullDataPath);
m = fileAllData{i,1}.(attivita{1,j}){s,1};

x = m(1,:)';
y = m(2,:)';
z = m(3,:)';
.....
s = s+1;

end


Main function:
.....
for j = 1:K
for i = 1:nSubjects
s = 1;
while s<=trials(j)

[x, y, z, s] = getXYZ(pathData, j, i, s);
end
end
end
...


What can be attributed to slowness? I do not know how to access data more efficiently. What can I try?







matlab performance function time






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 14:24









Sara SavioSara Savio

1416




1416








  • 2





    Have you tried profiling this function? You can do that by setting up a script which calls the function, and pressing "Run and Time" in the top bar. That'll tell you which parts of your function are the most time consuming. Run that, then edit the question to contain the result and investigate from there.

    – Adriaan
    Nov 22 '18 at 14:31











  • Second the suggestion on profiling, also - how much total data is there? Would it make more sense to read the file once and get the data in memory, then process it?

    – paisanco
    Nov 22 '18 at 14:32











  • I solve the problem with the suggestion of Adriaan, thank you very very much

    – Sara Savio
    Nov 22 '18 at 14:46











  • Sara, if you solved the problem, please post an answer here, and accept it. Thanks!

    – Cris Luengo
    Nov 22 '18 at 19:09











  • I bet your problem is in importdata. I’d suggest reading in the data only once, reading data is expensive.

    – Cris Luengo
    Nov 22 '18 at 19:10














  • 2





    Have you tried profiling this function? You can do that by setting up a script which calls the function, and pressing "Run and Time" in the top bar. That'll tell you which parts of your function are the most time consuming. Run that, then edit the question to contain the result and investigate from there.

    – Adriaan
    Nov 22 '18 at 14:31











  • Second the suggestion on profiling, also - how much total data is there? Would it make more sense to read the file once and get the data in memory, then process it?

    – paisanco
    Nov 22 '18 at 14:32











  • I solve the problem with the suggestion of Adriaan, thank you very very much

    – Sara Savio
    Nov 22 '18 at 14:46











  • Sara, if you solved the problem, please post an answer here, and accept it. Thanks!

    – Cris Luengo
    Nov 22 '18 at 19:09











  • I bet your problem is in importdata. I’d suggest reading in the data only once, reading data is expensive.

    – Cris Luengo
    Nov 22 '18 at 19:10








2




2





Have you tried profiling this function? You can do that by setting up a script which calls the function, and pressing "Run and Time" in the top bar. That'll tell you which parts of your function are the most time consuming. Run that, then edit the question to contain the result and investigate from there.

– Adriaan
Nov 22 '18 at 14:31





Have you tried profiling this function? You can do that by setting up a script which calls the function, and pressing "Run and Time" in the top bar. That'll tell you which parts of your function are the most time consuming. Run that, then edit the question to contain the result and investigate from there.

– Adriaan
Nov 22 '18 at 14:31













Second the suggestion on profiling, also - how much total data is there? Would it make more sense to read the file once and get the data in memory, then process it?

– paisanco
Nov 22 '18 at 14:32





Second the suggestion on profiling, also - how much total data is there? Would it make more sense to read the file once and get the data in memory, then process it?

– paisanco
Nov 22 '18 at 14:32













I solve the problem with the suggestion of Adriaan, thank you very very much

– Sara Savio
Nov 22 '18 at 14:46





I solve the problem with the suggestion of Adriaan, thank you very very much

– Sara Savio
Nov 22 '18 at 14:46













Sara, if you solved the problem, please post an answer here, and accept it. Thanks!

– Cris Luengo
Nov 22 '18 at 19:09





Sara, if you solved the problem, please post an answer here, and accept it. Thanks!

– Cris Luengo
Nov 22 '18 at 19:09













I bet your problem is in importdata. I’d suggest reading in the data only once, reading data is expensive.

– Cris Luengo
Nov 22 '18 at 19:10





I bet your problem is in importdata. I’d suggest reading in the data only once, reading data is expensive.

– Cris Luengo
Nov 22 '18 at 19:10












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433030%2fmatlab-function-works-very-slow%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433030%2fmatlab-function-works-very-slow%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?