필터 지우기
필터 지우기

"Unable to perform assignment because the size of the left and right side are not compatable... I am getting the following message: "Unable to perform assignment because the size of the left side is 1-by-47 and the size of the right side is 1-by-45"

조회 수: 1 (최근 30일)
for i=3:50 %length(OCT)
%temp = zeros;
temp = strsplit(OCT(i,1),'|');
clear length;
length = length(temp);
for spaces=1:length
OCT_Split_BULK(i,spaces) = "";
end
OCT_Split_BULK(i,:) = temp;
end
I tried to get around the issue by allocating within my loop... but I have tried multiple things and I am getting afraid that my code is becoming more and more inefficient.
This is for a research project on the US Tick Size Pilot program and I need to loop over a .mat file that I turned into a "12024072x1 string." The length of OCT is 12024072 but I set it to 50 for simplicities sake... The most common changes in the array are from 45 to 47 and vice versa...sdfdf
I can attach an excel file that has some rows but not all of them so you can get an idea for what it needs to look like. The excel file is been delimited by "|" (vertical bar) while I am attempting to delimit my data in Matlab.
I need to...
1) find out a more efficient way to delimit through a .mat file or string array
2) or find out a way to get around the error message...
I will link the files as well...

답변 (1개)

Bob Thompson
Bob Thompson 2019년 4월 15일
I would first begin by converting the strings into a cell array. This alone shoud remove the error message. From there you can create a for loop manually, or you can use cellfun to loop through each cell for you. Finally, I prefer regexp to strsplit, as it is much more versitile, but helps accomplish the same thing.
OCT = cellstr(OCT);
OCT_split_BULK = cellfun(@(x) regexp(x,'|','split'),OCT(3:end));
  댓글 수: 2
James Gressett
James Gressett 2019년 4월 16일
Hi Bob, thank you very much for the help. I tried your to use the cellfun and regexp command but it simply returned the same thing. Am I to use my cell array OCT in place of the "x" variable?
Bob Thompson
Bob Thompson 2019년 4월 16일
편집: Bob Thompson 2019년 4월 16일
No, when using cellfun you define an internal variable (I see x as the most common usage of this) which actually represents each cell of a cell array. So, no, you do not want to replace x with OCT because x is each cell in OCT, rather than the array as a whole.
'I tried your to use the cellfun and regexp command but it simply returned the same thing.'
So you're saying that you still get the array size error? Which line exactly is giving you the error? Are you using the loop and cellfun, or just one or the other?
Also, as a side note, I just noticed that you are using 'length' as a variable. It is generally considered bad practice to use any function name as a variable name, as it prevents you from using the function as a function, and overrides to a variable. If you do this, and then forget about it, it is highly likely to cause you problems later, especially if you are using something as common as 'length.'

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

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by