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;
}
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
add a comment |
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
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 inimportdata
. I’d suggest reading in the data only once, reading data is expensive.
– Cris Luengo
Nov 22 '18 at 19:10
add a comment |
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
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
matlab performance function time
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 inimportdata
. I’d suggest reading in the data only once, reading data is expensive.
– Cris Luengo
Nov 22 '18 at 19:10
add a comment |
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 inimportdata
. 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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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