### Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

## Looping the data along with deliminaters (please find the code below)

### Rakesh Yadav Kodari (view profile)

さんによって質問されました 2019 年 2 月 19 日

### Stephen Cobeldick (view profile)

さんによって コメントされました 2019 年 2 月 20 日
I have to read data from the serial port multiple times like
A = fscanf(t)
B = fscanf(t)
C = fscanf(t)
D = fscanf(t)
E = fscanf(t) and so on i had to do it manually. so i tried the code below for making it simple, and also i have deliminaters for example M and L
n = 10000;
% while loop execution
while( n < 10000 )
A= fscanf(t);
end

### Rakesh Yadav Kodari (view profile)

2019 年 2 月 19 日
Can I use while or for loop to get all the data in one vector?
Bob Nbob

### Bob Nbob (view profile)

2019 年 2 月 19 日
Do you know how many sets of data you're going to get? If so, yes it is possible to use a for loop. If not, a while loop is likely a better option.

### Rakesh Yadav Kodari (view profile)

2019 年 2 月 19 日
I dont know how many sets of data I am going to get, but i know where the data starts and ends. how can i use a while loop?

サインイン to comment.

## 1 件の回答

2019 年 2 月 19 日

### Bob Nbob (view profile)

2019 年 2 月 19 日

i = 0; % Initalize your index
while n < 10000; % Loop break condition
i = i+1; % Change index to next value
A(i) = fscanf(t); % Record data to index
n = ... % You need to define n. How will you break your loop? Check for end of data set maybe?
end

### Rakesh Yadav Kodari (view profile)

2019 年 2 月 20 日
I have made some possible changes and tried the code below:
i = 0;
n = 0;
while n < 10000
i = i+1;
A(i) = fscanf(t);
if strfind(A(i), '|') %End delim
break
end
end
but it says "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side."

### Rakesh Yadav Kodari (view profile)

2019 年 2 月 20 日
Is there any possible way that i can change the vector itself like A,B,C,D....to save the ans?
Stephen Cobeldick

### Stephen Cobeldick (view profile)

2019 年 2 月 20 日
@Rakesh Yadav Kodari: the default format for fscanf for serial objects is '%c'. As far as I can tell, this means that you could easily have multiple characters. Multiple characters cannot be allocated to one element of a char/numeric array. You could easily use a cell array, or check the size of the output before allocating to the array, or perhaps you just need to specify the format string to convert the data to numeric: which of these you need depends on your data and your algorithm, which you have not told us about.

サインイン to comment.

Translated by