필터 지우기
필터 지우기

Extracting data into different variables

조회 수: 5 (최근 30일)
Wei Jun Yap
Wei Jun Yap 2022년 11월 22일
편집: dpb 2022년 11월 23일
Hey there, I am trying to export the data file i got below.
As you can see, different country has different country code. How could I extract each data of a specific country into a variable?

답변 (2개)

dpb
dpb 2022년 11월 22일
"...could I extract each data of a specific country into a variable?"
You could do that, but don't -- use grouping variables or the higher-level tools like groupsummary and work on the data in situ in a table instead. Far superior way to go at virtually anything you can imagine to do with such data; the builtin facilities are astounding when you discover they're there...
  댓글 수: 2
Wei Jun Yap
Wei Jun Yap 2022년 11월 23일
ahh alright. But in this case i'll be working backwards to assign the respective year, and country to matrices in a variable. How would you do that in this case?
dpb
dpb 2022년 11월 23일
편집: dpb 2022년 11월 23일
Not sure (well, that's not right, am sure) I understand the question. Show us a small example of what you're trying to accomplish with what is available for input and desired output. Telling us the end objective besides what is seen as a step along the way is always beneficial to add context and guide the development of the path to the end objective; oftentimes there is a much straighter route to the end objective.
"... i'll be working backwards to assign the respective year, and country to matrices in a variable"
I think that's the conceptual issue here -- I'm saying most likely you don't have to (and shoudn't) be trying to assign to new variable(s) but extracting and using the given data directly from the table. You've already got it; efficiency would be to not create copies of the same thing.

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


MisterQuax
MisterQuax 2022년 11월 22일
Hello,
this is one possible solution for a table I created. If you want to use A afterward, you should convert it to a number.
data(1:10,1) = "RUS"
data(10:20,1) = "ROU"
data(10:20,2) = "1"
data(1:10,2) = "2"
data(10:20,3) = "3"
data(1:10,3) = "4"
A = data(data(:,1)=="ROU",2:end)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by