How to get rid of The RPC server is unavailable Error?

조회 수: 23 (최근 30일)
Susan
Susan 2020년 7월 10일
답변: Samuel Gray 2022년 1월 26일
Hi everyone,
I have a main folder with 10 subfolders in it. Each subfolder has 200 subfolders within them. in each of these 200 subfolders, I have 4 .csv files. I created a loop that the code opens a subfolder, do what I want and then move to the next one as follows
D = 'C:\Users\....\Data\'
S1 = dir(fullfile(D,'*'));
N1 = setdiff({S1([S1.isdir]).name},{'.','..'});
A = {};
B = {};
C = {};
for kk = 1 : 10
kk
D1 = fullfile(D, N1{kk});
S2 = dir(fullfile(D1,'*'));
N2 = setdiff({S2([S2.isdir]).name},{'.','..'});
for ii = 1 : 200
ii
T1 = dir(fullfile(D1,N2{ii},'*'));
C = {T1(~[T1.isdir]).name};
for jj = 1 : numel(C)
if jj == 1
F = fullfile(D1,N2{ii},C{jj});
[n,~,~] = xlsread(F);
elseif jj == 2
F = fullfile(D1,N2{ii},C{jj});
m = csvread(F);
elseif jj == 3
F = fullfile(D1,N2{ii},C{jj});
p = csvread(F);
elseif jj == 4
F = fullfile(D1,N2{ii},C{jj});
q = csvread(F);
end
end
A{kk, ii} = complex(p, m);
B{kk, ii} = q(:,1) - q(1,1);
C{kk, ii} = n(2);
end
end
when I run the code, I've got the "RPC server is unavailable" error on kk=2, ii =21. However, when I check the code manualy for kk=2, ii =21 it works perfectly. Any idea how I can get rid of this error? How I can improve the code to run faster? Any input would be greatly appreciated.

채택된 답변

Walter Roberson
Walter Roberson 2020년 7월 10일
I can think of three potential solutions:
  • put a pause after the xlsread(); or
  • instead of using xlsread() look in the file exchange for xlsread1(); or
  • switch to readtable() instead of xlsread(). Note that if you switch to readtable() then you can probably use it or readmatrix() instead of the csvread().
That is, I suspect that the connection to the excel server is not ready in time, so you either need to slow down access or use the excel server differently or avoid using the excel server.
  댓글 수: 1
Susan
Susan 2020년 7월 10일
Thank you so much for your reply! I put a pause after the xlsread for 3sec, i.e., pause(3). But it wasn't able to solve the issue.
However, when I switched to readtable instead of xlsread(), it works perfectly.
Thanks again for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Samuel Gray
Samuel Gray 2022년 1월 26일
https://www.mathworks.com/help/matlab/ref/comserver.html

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by